marsie Posted November 30, 2009 Share Posted November 30, 2009 Hi I'm trying to write a script that will display an image from a folder and the description from the database. The image is displaying and the text is displaying but not in the order I would like. How can I specify which image goes with it's correct description? See code below: <style type="text/css"> <!-- body,td,th { font-family: Arial, Helvetica, sans-serif; } --> </style> <?php //Connect to Directory $dir="images/bracelets"; $path=getcwd().'/'.$dir; $handle=opendir($path); //Open Directory $i=1; $handle=opendir($path); //Select .jpg from Directory while ($file=readdir($handle)){ if (strpos($file, '.jpg')){ //Connect to Database mysql_connect("localhost","root",""); //Select the Database mysql_select_db("girsha"); //Select All data from table $query = mysql_query("SELECT * FROM producttbl"); while($row = mysql_fetch_array($query)){ { $ProdName = $row['ProdName']; $ProdDescription = $row['ProdDescription']; $Price = $row['Price']; //Display Product Information from DB echo $ProdName." - ".$ProdDescription."<br /><br>"." € " .$Price."<br /><br>"; //Display images from Directory $images = "<img src=\"images/bracelets/$file\" alt=\"pic$i\" border=\"0\" height=\"120px\" width=\"120px\" hspace=\"5px\" />"; echo $images."<br /><br>"; $i++; } } } } ?> Link to comment https://forums.phpfreaks.com/topic/183458-image-display-with-description-from-database/ Share on other sites More sharing options...
lemmin Posted November 30, 2009 Share Posted November 30, 2009 It seems like you don't have any relationship set up between the pictures and their products. I would suggest adding a column to your table for image location. That way, you don't have to iterate through the directory either. Link to comment https://forums.phpfreaks.com/topic/183458-image-display-with-description-from-database/#findComment-968396 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.