abhi_madhani Posted June 1, 2010 Share Posted June 1, 2010 Hi Friends, I have created a search page, that displays the results for particular entered search terms, something similar to Google Image Search engine. I am trying to display the first five records of the results on 1st row, and next five records on 2nd row, and next five records on 3rd row and so on Can any of you please guide me as to how can I achieve this. I have attached a sample code of my page which reads each record from the database and displays them. <?php echo " <html> <body> <table> <tr>"; $viewprodSQL="select * from product where fieldname='term' "; $exeviewprodSQL=mysql_query($viewprodSQL) or die (mysql_error); while ($thisviewprodarray=mysql_fetch_array($exeviewprodSQL)) { echo " <td> <img src=".$imgloc." width='125' height='125'> </td>"; } echo " </tr> </table> </body> </html>"; ?> Link to comment https://forums.phpfreaks.com/topic/203555-display-5-items-per-row-of-table/ Share on other sites More sharing options...
kenrbnsn Posted June 1, 2010 Share Posted June 1, 2010 Put a counter in: <?php echo " <html> <body> <table> <tr>"; $viewprodSQL="select * from product where fieldname='term' "; $exeviewprodSQL=mysql_query($viewprodSQL) or die (mysql_error); $n = 0; while ($thisviewprodarray=mysql_fetch_array($exeviewprodSQL)) { echo " <td><img src=".$imgloc." width='125' height='125'></td>"; $n++; if ($n % 5 == 0) echo '</tr><tr>'; } echo " </tr> </table> </body> </html>"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/203555-display-5-items-per-row-of-table/#findComment-1066279 Share on other sites More sharing options...
abhi_madhani Posted June 1, 2010 Author Share Posted June 1, 2010 Hi, Ken Thanks for such a simple yet unique solution. I completely agree that PHPfreaks is the ultimate resource for PHP related help. Regards, Abhishek Madhani Link to comment https://forums.phpfreaks.com/topic/203555-display-5-items-per-row-of-table/#findComment-1066311 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.