I have a mysql table full of pictures(their path) that are owned by many different users.

I need to run the following query and return the results into a 5 column table. The number of rows will be however many it takes to display all the pictures.

My query is as following:

SELECT * FROM pictures WHERE email='$_GET and date >= DATE_SUB(NOW(), INTERVAL 30 DAY);

while ($row = mysql_fetch_assoc($sql)){

echo "<table class='results'>
<tr><td><img src='.$row.'"></td><td><img src='.$row.'"></td><td><img src='.$row.'"></td><td><img src='.$row.'"></td><td><img src='.$row.'"></td></tr>
</table>";

I just am confused on how to get it to make it do this for 5 columns, because I can't hard code the </tr> or </table> for I don't know how many pictures there are per user. Some users may have 3 pictures and some may have 50.

Any ideas?

Recommended Answers

All 2 Replies

Member Avatar for P0lT10n

you can do inside the while an if condition and a counter... if the counter is mayor than 5 dont show anything...

Here is code:

<?	
	$sql = "SELECT * FROM pictures WHERE email='$_GET['email'] and date >= DATE_SUB(NOW(), INTERVAL 30 DAY)";	
	$res = mysql_query($sql);
	$cnt = 0;
	$numCol = 5;
	
	echo "<table border='1' class='results'>";
	while ($row = mysql_fetch_assoc($res))
	{
		$cnt++;
		if($cnt==1 || ($cnt-1)%$numCol==0)
			echo '<tr>';
		
		echo "<td><img src=".$row['picture']."></td>";
				
		if($cnt%$numCol==0)
			echo '</tr>';
	}
	echo "</table>";
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.