SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast urbanformula's Avatar
    Join Date
    Apr 2004
    Location
    Burlington, VT .. USA
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    2 Column Results Loop Problem

    first off, i dont get any errors, seems to work ok, BUT
    i have mysql results in what should be 2 columns and however many rows.
    heres the code:

    while($row = mysql_fetch_assoc($result))
    {
    echo "<td width=\"410\">".
    "<div id=\"storeBox\">
    <div id=\"featured_thumb\"><img src=\"../storeimgs/thumbs/".$row["image"]."\" width=\"115\" height=\"115\" /></div>
    <div id=\"featured_info\">
    Wine: &nbsp;<strong>".$row["title"]."</strong><br />
    Region: &nbsp;<strong>".$row["region"]."</strong><br />
    Vintage: &nbsp;<strong>".$row["year"]."</strong><br />
    Price: &nbsp;<strong>$".$row["price"]."</strong><br /><br />
    <a href=\"store_details.php?id=".$row["id"]."\"><img src=\"../images/view_productbtn.gif\" width=\"78\" height=\"13\" border=\"0\" alt=\"\" /></a>

    </div>
    </div>
    </div>
    <img src=\"../images/featured_spacerbaer.gif\" width=\"407\" height=\"20\" alt=\"\" /><br /><br />"
    ."</td>";
    $i = $i + 1; //add 1 to $i
    if ($i == 2) { //when you have echoed 2 <td>'s
    echo "</tr><tr>"; //echo a new row
    $i = 1; //reset $i
    }
    }

    now it makes two columns for the first two results then just cascades the rest in the left column down, any thoughts would be great
    thanks.

  2. #2
    SitePoint Enthusiast jcarouth's Avatar
    Join Date
    Sep 2006
    Location
    College Station, TX
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hopefully you assigned a value to $i before the line $i = $i + 1 but your problem is that you are setting $i to 1 inside the if block. then you add 1 to $i and test if it if is equal to 2. if it is you print the end of the table row. see the problem? $i needs to be set to 0 inside the if block.

  3. #3
    SitePoint Enthusiast urbanformula's Avatar
    Join Date
    Apr 2004
    Location
    Burlington, VT .. USA
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    works like a charm, thanks jcarouth


Bookmarks

Posting Permissions

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