# PHP loop through database and limit number of entries

**URL:** <https://forum.kirupa.com/t/php-loop-through-database-and-limit-number-of-entries/293955>\
**Category:** programming\
**Created:** [August 6, 2009, 9:30am UTC](https://forum.kirupa.com/t/php-loop-through-database-and-limit-number-of-entries/293955 "2009-08-06T09:30:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gilbertsavier](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@gilbertsavier](https://forum.kirupa.com/u/gilbertsavier)\
**Post date:** [August 6, 2009, 9:30am UTC](https://forum.kirupa.com/t/php-loop-through-database-and-limit-number-of-entries/293955/1 "2009-08-06T09:30:34Z")

</div>

Hello,  
Going to try to explain this as best I can. I have a bunch of stuff in a database and I need to display this info within a table. This isn’t a problem at all but, I need it to only display 3 td tags per line and then move on to the row.

so i need it to do :

code:

\<table\>  
\<tr\>  
\<td\>My First Row\</td\>  
\<td\>My First Row 2\</td\>  
\<td\>My First Row 3\</td\>  
\</tr\>

\<tr\>  
\<td\>My Second Row\</td\>  
\<td\>My Second Row 2\</td\>  
\<td\>My Second Row 3\</td\>  
\</tr\>  
\</table\>

and continue to do this through every entry in the database table.

so I have something like this that will display the info:

code:

for ($i = 1; $i \<= $num; $i++){

```
    $chairArray = mysql_fetch_array($chairResult);
    $chairName = $chairArray['name'];
    $chairDescription = $chairArray['description'];
    $chairImage = $chairArray['image'];
    
    echo "&lt;tr&gt;";
    echo "&lt;td&gt;";
    echo "&lt;img src=\"images/catalog/ottomans/thumbs/$chairImage\" width=\"157\" height=\"147\" /&gt;";
    echo "&lt;br /&gt;";
    echo $chairName;
    echo "&lt;/td&gt;";
    echo "&lt;/tr&gt;";
    
    
}
```
