dbones Posted November 17, 2006 Share Posted November 17, 2006 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 More sharing options...
AndyB Posted November 18, 2006 Share Posted November 18, 2006 I think we need a much better description of what you are hoping to do. The description you gave, and the code you provided, aren't making clear just what problem you have. Link to comment https://forums.phpfreaks.com/topic/27639-displaying-images-in-order/#findComment-126439 Share on other sites More sharing options...
jsladek Posted November 18, 2006 Share Posted November 18, 2006 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 Link to comment https://forums.phpfreaks.com/topic/27639-displaying-images-in-order/#findComment-126446 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.