Jump to content

Display 5 items per row of table


abhi_madhani

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.