googlit Posted June 25, 2010 Share Posted June 25, 2010 Hi'yall im developing a page in where i want to display multiple products within a category and there associated image the code i have so far is : <?php require_once('auth.php'); ?> <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Products</title> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Products</h1> <a href="member-index.php">Home</a> | <a href="logout.php">Logout</a> <p>Please choose a product below for further information</p> <div id="page-layout"> <div id="main-area"> <?php $sql = 'SELECT * FROM products WHERE catagory_id=1 ORDER BY id';//catagory id 1 = wine fridges $result = $db->query($sql); $output[] = ''; while ($row = $result->fetch()) { $output[] = '<div class="product-box"><div class="pbox-inner"><h1>"' .$row['Name'] //i want to display the image here .'"</h1><br /><b>Model No: </B> ' .$row['Model_No'] .'<br /><b>Description: </b>' .$row['Description'] .'<br /><b>Price: </b>£' .$row['Price'] .'<br /> </div><div class="pbox-adtocart"> <div align="right"><a href="cart.php?action=add&id='.$row['id'].'"><img src="images/moreinfo.jpg" border="0" /></a></div></div> </div>'; } $output[] = ''; echo join('',$output); ?> </div> <div id="main-right"> <div class="mb-holder"> <div class="mb-top"></div> <div class="mb-mid"> <?php echo writeShoppingCart(); ?> </div> <div class="mb-base"></div> </div> </div> </body> </html> the image location is stored in the products table as image_id, all i am looking for is a way to echo the image that releate to the id on the table entries. i have tried several way but not had any luck. can anybody help or point me in the right direction. Link to comment https://forums.phpfreaks.com/topic/205845-help-displaying-an-image/ Share on other sites More sharing options...
kev@num Posted June 25, 2010 Share Posted June 25, 2010 echo '<img src="'.$row['image_id'].'">'; not sure if this is what you are after. or to put in place :- .'<img src="'. $row['image_id'] .'">' Link to comment https://forums.phpfreaks.com/topic/205845-help-displaying-an-image/#findComment-1077149 Share on other sites More sharing options...
googlit Posted June 25, 2010 Author Share Posted June 25, 2010 echo '<img src="'.$row['image_id'].'">'; not sure if this is what you are after. or to put in place :- .'<img src="'. $row['image_id'] .'">' thanks for that, i tried that previously but kept getting error, think i was commenting out wrong...... also when i display this in the browser the 'Name' form the data base is enclosed with double quotes which i cant seem to get rid of...... any ideas? Link to comment https://forums.phpfreaks.com/topic/205845-help-displaying-an-image/#findComment-1077156 Share on other sites More sharing options...
bluejay002 Posted June 25, 2010 Share Posted June 25, 2010 placing this code will work fine: ... <img src="'.$row['image_location'].'" border="0" /> ... just place there the field that contains the image location. It should work just fine. If there was an error, post up the code where the error occurs (a few lines before and after) and post the error it returns so we can see where's the pitfall. bluejay, Link to comment https://forums.phpfreaks.com/topic/205845-help-displaying-an-image/#findComment-1077165 Share on other sites More sharing options...
googlit Posted June 25, 2010 Author Share Posted June 25, 2010 Got the image working however no there are double quotes displaying in the browser at the beginning of the 'NAME' output and then a set of double quotes immediately after the image. (see image attached) my code is as follows: <?php $sql = 'SELECT * FROM products WHERE catagory_id=' . intval($_GET['id']);//catagory id 1 = wine fridges $result = $db->query($sql); $output[] = ''; while ($row = $result->fetch()) { $output[] = '<div class="product-box"><div class="pbox-inner"><h1>"' .$row['Name'] .'<img src="images/'.$row['image'].'" width="70">' .'"</h1><br /><b>Model No: </B> ' .$row['Model_No'] .'<br /><b>Description: </b>' .$row['Description'] .'<br /><b>Price: </b>£' .$row['Price'] .'<br /> </div><div class="pbox-adtocart"> <div align="right"><a href="cart.php?action=add&id='.$row['id'].'"><img src="images/moreinfo.jpg" border="0" /></a></div></div> </div>'; } $output[] = ''; echo join('',$output); ?> [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/205845-help-displaying-an-image/#findComment-1077175 Share on other sites More sharing options...
bluejay002 Posted June 25, 2010 Share Posted June 25, 2010 $output[] = '<div class="product-box"><div class="pbox-inner"><h1>"' .$row['Name'] .'<img src="images/'.$row['image'].'" width="70">' .'"</h1><br /><b>Model No: </B> ' ... close the H1 right after the name, not after the image tag. Do this instead: $output[] = '<div class="product-box"><div class="pbox-inner">' .'<h1>"'.$row['Name'].'"</h1>' .'<img src="images/'.$row['image'].'" width="70">' .'<br /><b>Model No: </B> ' ... Link to comment https://forums.phpfreaks.com/topic/205845-help-displaying-an-image/#findComment-1077183 Share on other sites More sharing options...
googlit Posted June 25, 2010 Author Share Posted June 25, 2010 Thanks... Worked perfik! LOL cheers Link to comment https://forums.phpfreaks.com/topic/205845-help-displaying-an-image/#findComment-1077192 Share on other sites More sharing options...
bluejay002 Posted June 25, 2010 Share Posted June 25, 2010 good for you. Link to comment https://forums.phpfreaks.com/topic/205845-help-displaying-an-image/#findComment-1077196 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.