SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
-
May 31, 2003, 21:29 #1
- Join Date
- Mar 2002
- Location
- Silicon Valley
- Posts
- 3,626
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
Displaying Query Results in Columns the Rows
I'm trying to figure out how to display an unknown quantity of products where 3 products are diplayed per row until all products are displayed. I have no problem diplaying one per row, but telling PHP to display 3 and the n go to the next row is somethong I can't quite fathom. Here is an example of what I'm hoping to diplay:
Code:<table width="100%" border="0"> <tr> <td>Product 1</td> <td>Product 2</td> <td>Product 3</td> </tr> <tr> <td>Product 4</td> <td>Product 5</td> <td>Product 6</td> </tr> <tr> <td>Product 7</td> <td>Product 8</td> <td>Product 9</td> </tr> </table>
PHP Link Directory Script -easy to create and profitable too
What Google "thinks"
Does Google Trust You?
What it means to be human
-
May 31, 2003, 21:51 #2
- Join Date
- Jan 2003
- Location
- New York
- Posts
- 885
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Try this:
Code:. . . $column = 0; while ($product = mysql_fetch_array($products)) { if ($column == 0) { echo("<tr>"); } echo ("<td>$product</td>"); $column++; if ($column >= 3) { $column = 0; echo("</tr>"); } } if ($column != 0) { echo("</tr>"); } . . .
Bookmarks