Jump to content

Help displaying an image


googlit

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

                     $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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.