Jump to content

Displaying images in order


dbones

Recommended Posts

I am trying to display 5 images from my folder location alongside the products in my database. How do I display the images in order without looping the data from the database

$query='SELECT * FROM items ORDER BY id';
if ($r=mysql_query($query)){
while($row = mysql_fetch_array($r)){
for($n=1; $n<5; $n++){
print "<p><image src = 'http://diabri.100webspace.net/images/book$n.jpg'> </p>
<p><b>Title: {$row['title']}</b>
<br>Author: {$row['author']}
<br>Price: {$row['price']}</p>";
}
}
}else{
die('<p>Could not retrieve the data because:<br>'.mysql_error()."<br>.
The query was $query.</p>");
}
mysql_close();
Link to comment
https://forums.phpfreaks.com/topic/27639-displaying-images-in-order/
Share on other sites

best thing to do would be to add a text feild to the database and put the name of the image in it. Then replace this...
[code]print "<p><image src = 'http://diabri.100webspace.net/images/book$n.jpg'> </p>[/code]
With this
[code]print "<p><image src = 'http://diabri.100webspace.net/images/{$row['image']}'> </p>[/code]
Better Approach if you ask me

-John Sladek

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.