I am using a While loop to dispay data stored in a mysql database I would like all the data to be displayed on a single line instead of being displying below the prevoius.

while($row = mysql_fetch_assoc($popular)){
echo"<figure>
<div align=\"center\">
<a href=\"\"><img src=\"images/" . $row['product_img'] . ".png\" alt=\"" . $row['alt_desc'] . "\"></a>
<figcaption><p>" . $row['product_name'] . "<br>
<b>£" . $row['product_price'] . "</b>
</p></div></figure>";  
}

I think it is something to do with the figure element as when I only looped this line:

<a href=\"\"><img src=\"images/" . $row['product_img'] . ".png\" alt=\"" . $row['alt_desc'] . "\"></a>

The images would be disped next to each other not not listed down the page.
Does anyone how any ideas how I could solve this problem.

Member Avatar
LastMitch

The images would be disped next to each other not not listed down the page.

You mean a single line not a inline. A inline you need CSS to do that another words CSS needs to be involve with the code.

It should look like this

<div class="center" style="display:inline-block;">
<a href=\"\"><img src=\"images/" . $row['product_img'] . ".png\" alt=\"" . $row['alt_desc'] . "\"></a>
</div>

The code I provided is a inline-block.

It's a single line or inline which I'm not sure what you are trying to do.

If that's not what you want then you really need to explain it very clearly.

I managed to solive it by using

float:left;

Style sheet provide us a lots of attributes to do lots of things. Where we not get the need any java script. CSS is really helpful for us.

You have no closing tag for the figcaption which may cause layout problems

<figure>
<div align=\"center\">
<a href=\"\"><img src=\"images/" . $row['product_img'] . ".png\" alt=\"" . $row['alt_desc'] . "\"></a>
<figcaption><p>" . $row['product_name'] . "<br>
<b>£" . $row['product_price'] . "</b>
</p></div></figure>