Jump to content

Image Display with Description from Database


marsie

Recommended Posts

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++;

}

}

}

}

?>

 

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.