My sql image links in table

Reply

Join Date: Jan 2008
Posts: 20
Reputation: duttydea is an unknown quantity at this point 
Solved Threads: 0
duttydea duttydea is offline Offline
Newbie Poster

My sql image links in table

 
0
  #1
Jan 20th, 2008
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

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

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

Thanks in advance
Last edited by duttydea; Jan 20th, 2008 at 4:20 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 84
Reputation: johnsquibb is an unknown quantity at this point 
Solved Threads: 14
johnsquibb's Avatar
johnsquibb johnsquibb is offline Offline
Junior Poster in Training

Re: My sql image links in table

 
0
  #2
Jan 20th, 2008
1. execute your sql statement
2. use mysql_fetch_array to capture the data into an array (eg.
  1. $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):

  1. //create sql
  2. $sql="SELECT * FROM prod_listing";
  3.  
  4. //execute query
  5. $result=mysql_query($sql,$connection) or die('could not execute query');
  6.  
  7. $html_content = '<table>';
  8.  
  9. while($row = mysql_fetch_array($result))
  10. {
  11. $html_content .='<tr><td><image src="'.$row['Product_picur1'].'" /></td></tr>';
  12. }
  13.  
  14. $html_content.='</table>';
  15.  
  16. 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.
Last edited by johnsquibb; Jan 20th, 2008 at 6:10 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC