Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By low tech

Thread: Using PHP to Create an Ordered List

  1. #1
    New Coder
    Join Date
    Sep 2011
    Location
    Bournemouth
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Using PHP to Create an Ordered List

    Hello,

    I'm having a go at an online exercise and the task at the end of my script (directly relating to creating an ordered list is not working. I resorted to copying it from the exercise script just to get used to the format but it still didn't work. I suspect that the script relies on the previous exercise where I had to create a do while loop (although please tell me if the task works independently:

    Here is my code:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
      
    <html xmlns="http://www.w3.org/1999/xhtml"  xml:lang="en" lang="en"> 
    <head> 
    <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" /> 
    <title>If, Else, Elseif Statement</title> 
    </head> 
       
    <body> 

    <?php


    $x
    =0;
    $y "abc, ";

    while (
    $x <= "8") {
    echo  
    $y;
    $x++;

    }
    echo 
    "<br/>";

    $x=1;
    do {echo 
    'xyz, ';
    $x++; }
    while (
    $x <=9);

    //Generated Ordered List Wohhhh not covered this before!!

    echo "\n <ol>";

    for (
    $x='A'$x=<'G'$x++){

    echo 
    "<li>Item $x</li>\n"; }

    echo 
    "\n </ol>";

    ?>

    </body>
    </html>
    I'm sure you will know in 5 secs where I have gone wrong!!

    Thanks,

    Beanie.
    Last edited by bgareth; 05-19-2014 at 10:39 AM. Reason: Resolved :-)

  • #2
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Try


    PHP Code:
    echo "<ol>"

    for ( 
    $x='A'$x<='G'$x++ ){ 

    echo 
    "<li>Item $x</li>";

    }
    echo 
    "</ol>"
    Last edited by low tech; 05-19-2014 at 10:42 AM.
    bgareth likes this.
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • #3
    New Coder
    Join Date
    Sep 2011
    Location
    Bournemouth
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks for this low tech :-)

    I realised after trawling through the code and before seeing what you wrote:

    PHP Code:
    for ($x='A'$x=<'G'$x++){ 
    There should not have been an = in the $x=<'G'; and it should have read $x<'G';

    Derrr - so you made a slightly different suggestion swapping this around - how does your suggestion work out of curiosity and is there any point of having an = sign, if so, why did my change work?

    Not criticising your suggestion at all, just trying to understand :-)

    Thanks and Kind Regards,

    Beanie.

  • #4
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Hi

    =< is just wrong syntax

    see
    PHP: Comparison Operators - Manual


    try $x<'G;

    try $x<='G'

    and see what you get.
    Last edited by low tech; 05-19-2014 at 10:50 AM.
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •