954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

echo mysql resutls to a table....

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['email'] and date >= DATE_SUB(NOW(), INTERVAL 30 DAY);

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

echo ".$row[.$row[.$row[.$row[.$row[";

I just am confused on how to get it to make it do this for 5 columns, because I can't hard code the or 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?

dschuett
Junior Poster
121 posts since Aug 2010
Reputation Points: 9
Solved Threads: 2
 

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

P0lT10n
Posting Whiz in Training
235 posts since Apr 2010
Reputation Points: 13
Solved Threads: 30
 

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>";
?>
vibhaJ
Posting Shark
931 posts since Apr 2010
Reputation Points: 161
Solved Threads: 183
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: