How can i Load images in to each cell of a table based on its product id?

The picture url is stored in field: Product_picurl

SELECT `Product_id`,`Product_Name` , `Product_picurl`
FROM `prod_listing` where `Product_id` ="$ID"

I have looked around for a photogallery script but cant find one!!

Thanks in advance

1. execute your sql statement
2. use mysql_fetch_array to capture the data into an array (eg.

$row=mysql_fetch_array($sql_result);

)
3. Cycle through the array to output the image urls to the page with some sort of loop (foreach, for, while, whatever fits your script/writing style)

that's the theory behind it.

here's a little sample (very quick and messy mind you, but will help you get the idea):

//create sql
$sql="SELECT * FROM prod_listing";

//execute query
$result=mysql_query($sql,$connection) or die('could not execute query');

$html_content = '<table>';

while($row = mysql_fetch_array($result))
{
	$html_content .='<tr><td><image src="'.$row['Product_picur1'].'" /></td></tr>';
}

$html_content.='</table>';

echo $html_content;

that gets all the pictures into a table, in order.

to get them in some sort of order, try using the ORDER BY clause in your sql, such as in:

$sql="SELECT * FROM prod_listing where Product_id ='$ID' ORDER BY [I]some_field_here[/I] ASC;";

there are multitudes of other approaches you could use to improve this, but maybe this will give you a start.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.