DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   My sql image links in table (http://www.daniweb.com/forums/thread105515.html)

duttydea Jan 20th, 2008 4:18 pm
My sql image links in table
 
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

johnsquibb Jan 20th, 2008 6:00 pm
Re: My sql image links in table
 
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 some_field_here ASC;";

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


All times are GMT -4. The time now is 11:11 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC