tauchai83 Posted December 28, 2006 Share Posted December 28, 2006 can some1 guide me on how to link a jpg images to the available item? what should I confifure in MYSQL db? or any special coding needed? my code look like this:[code]<?php$link = mysql_connect('localhost', 'root', '');if (!$link) { die('Not connected : ' . mysql_error());}$db_selected = mysql_select_db('tcmdb', $link);if (!$db_selected) { die ('Can\'t use the Database: ' . mysql_error());}$sql = 'SELECT Item_id,Item_pic,Item_desc, Unit_price FROM Item ORDER BY Item_id';$result = mysql_query($sql);$output[] = '<table border="3"><tr><td>';while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $output[] = '<tr><td>'.$row['Item_pic'].' <td>'.$row['Item_desc'].' <td>Price:'."".'RM'.$row['Unit_price'].' <td><a href="cart.php?action=add&id='.$row['Item_id'].'">Add to cart</a></td></tr>';}$output[] = '</td></tr></table>';echo join('',$output);?>[/code]eveything is fine except the images appear in words...how to solve this prob? please help..thanksss Link to comment https://forums.phpfreaks.com/topic/32046-retrieved-images-from-database/ Share on other sites More sharing options...
craygo Posted December 28, 2006 Share Posted December 28, 2006 first why are you putting your output into an array. just echo it out or put into a single variable. but it is up to you :)[code]<?php$link = mysql_connect('localhost', 'root', '');if (!$link) { die('Not connected : ' . mysql_error());}$db_selected = mysql_select_db('tcmdb', $link);if (!$db_selected) { die ('Can\'t use the Database: ' . mysql_error());}$sql = 'SELECT Item_id,Item_pic,Item_desc, Unit_price FROM Item ORDER BY Item_id';$result = mysql_query($sql);$output = '<table border="3"><tr><td>';while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $output .= '<tr><td><img src="path/to/image/'.$row['Item_pic'].'"><td>'.$row['Item_desc'].' <td>Price:'."".'RM'.$row['Unit_price'].' <td><a href="cart.php?action=add&id='.$row['Item_id'].'">Add to cart[/url]</td></tr>';}$output .= '</td></tr></table>';echo $output;?>[/code]Ray Link to comment https://forums.phpfreaks.com/topic/32046-retrieved-images-from-database/#findComment-148749 Share on other sites More sharing options...
tauchai83 Posted December 28, 2006 Author Share Posted December 28, 2006 the coding only work for one picture...i put the output in array because it is easier to display all in a table. I doing a shopping website which have several items in a table to view. How about I have many pictures to put? is it cannot use array? Link to comment https://forums.phpfreaks.com/topic/32046-retrieved-images-from-database/#findComment-148766 Share on other sites More sharing options...
craygo Posted December 28, 2006 Share Posted December 28, 2006 How many pictures are in the table??Are all the pictures in a separate column?Are you storing the actual picture in the table or just the name??Maybe post your table structure and folder structureRay Link to comment https://forums.phpfreaks.com/topic/32046-retrieved-images-from-database/#findComment-148776 Share on other sites More sharing options...
tauchai83 Posted December 29, 2006 Author Share Posted December 29, 2006 answer:There are total 6 pictures in the tableThese pictures should be displayed in the same column. In the webpage view, There are four column in the table. First column to display picture, followed by item description,price and final column is the cloumn reserved for "add to cart". --> I'm talking about the display of the pages to the user and not databases.I just store the name of the pictures in the table. For instance, BirdNest.jpg...the path to the folder as like this: tcm/images/BirdNest.jpg tcm is the folder put in WWW folder.the table structure as following:Field Type Collation Attributes Null Default Extra Action Item_id int(11) No auto_increment Item_barcode varchar(14) utf8_general_ci No Item_desc varchar(100) utf8_general_ci No [color=red]Item_pic varchar(64) utf8_general_ci No [/color] Supplier_id int(11) No Category_id int(11) No Minimum_qty int(2) No Qty_on-hand varchar(3) utf8_general_ci No Supplier_price decimal(15,2) No Unit_price decimal(15,2) No Expire_Date varchar(20) utf8_general_ci No Product_ordered int(3) No For Item_pic column, i trying by inserting value BirdNest.jpg which do not work stil..plz help..thanks! Link to comment https://forums.phpfreaks.com/topic/32046-retrieved-images-from-database/#findComment-149281 Share on other sites More sharing options...
craygo Posted December 29, 2006 Share Posted December 29, 2006 Just to get this straight, there is only one picture per row, correct?? What I mean is, you do not have 6 picture names in the Item_pic column? Link to comment https://forums.phpfreaks.com/topic/32046-retrieved-images-from-database/#findComment-149318 Share on other sites More sharing options...
tauchai83 Posted December 30, 2006 Author Share Posted December 30, 2006 For DB, yes...it's only one picture per row. For display in webpages, also one picture per row in the <table> tag.Craygo, all u talking here is about DB rite? ur table could be the <table> tag or database table. haha...confused with ur question somehow coz i'm newbies in PHP.:)the 6 pictures name is in DB Item_pic column already. Link to comment https://forums.phpfreaks.com/topic/32046-retrieved-images-from-database/#findComment-149599 Share on other sites More sharing options...
tauchai83 Posted December 31, 2006 Author Share Posted December 31, 2006 Ray,should I use the foreach keyword to solve this prob? How to solve it in the efficient way....i going 2 retrieve all pictures but in one row per row. One row one picture. I use array to display all in once but problems with the pictures column...Hope you can modify my code...i had tried so many ways and do not work still... Link to comment https://forums.phpfreaks.com/topic/32046-retrieved-images-from-database/#findComment-150151 Share on other sites More sharing options...
tauchai83 Posted January 1, 2007 Author Share Posted January 1, 2007 Ok. Ray...i used ur method by retriving one row of images and just echo it using if statement....i think this is the best way....:)...thanks lot..the problems therefore is solved with the suggestion from Craygo...Thanks..:) Link to comment https://forums.phpfreaks.com/topic/32046-retrieved-images-from-database/#findComment-150775 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.