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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.