Jump to content

while loop to populate a table


RobertSubnet

Recommended Posts

Hello all. I am trying to use a while loop to populate a table with pictures and a short description under the pictures. It should look something like this:

 

pic1  pic2  pic3

text  text  text

 

pic4  pic5  pic6

text  text  text

 

etc.

 

I am using PHP and MySQL to get the pictures and text data. The tricky part is getting the table populated correctly. What I currently have looks like this:

 

pic1  pic1  pic1

text  text  text

 

pic2  pic2  pic2

text  text  text

 

etc.

 

I understand why the first row is all the same picture. What I don't know is how to get pic1, pic2, pic3 on the first row.

 

Here is my code:

 

while ($row = mysql_fetch_array($gallery_query_result)) {

$photo1 = $row['photo1'];


echo "<table>";
echo "<tr><td>";
echo "<img src = $photo1 /><br/>";
echo "short description";
echo "</td><td>";
echo "<img src = $photo1 /><br/>";
echo "short description";
echo "</td><td>";
echo "<img src = $photo1 /><br/>";
echo "short description";
echo "</td></tr>";
echo "</table>";

//close while loop
}

 

Is a table not the best way to output the  pictures and text? Any suggestions would be much appreciated.

 

Thanks!!

 

 

Link to comment
https://forums.phpfreaks.com/topic/168391-while-loop-to-populate-a-table/
Share on other sites

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.