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 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    51
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Is there a problem with my if() loop?

    Does anyone know why I am not getting a new HTML table <TR> after 8 products, with this code? I can't figure it out. :shrugs:

    PHP Code:
    while ($row mysql_fetch_assoc($result)) {
        echo 
    '
            <TD>
                <A href="/products/'
    .$row['id'].'/">'.$row['id'].'</A>
            </TD>
        '
    ;
        
    $listing++;
        if (
    $listing == 8) {
            echo 
    '
        </TR>
        <TR>
            <TD>
                <BR>
            </TD>
            '
    ;
            
    $listing 0;
        }


  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,353
    Thanks
    61
    Thanked 529 Times in 516 Posts
    Try this:

    PHP Code:
    //This bit is important
    $listing 0;

    while (
    $row mysql_fetch_assoc($result)) 
       {
        echo <<<STOP
            <TD>
                <A href="/products/$row
    [id]/">$row[id]</A>
            </TD>

    STOP;    

        $listing++;

        if ($listing == 8)
          {
            echo <<<STOP
        </TR>
        <TR>
            <TD>
                <BR>
            </TD>

    STOP;

            
    $listing 0;
           }
       } 
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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