Jump to content

Display an image from Server


cdoyle

Recommended Posts

Hi,

 

I've been searching the forum, but haven't found the answer to this.

I have a feeling it will be an easy one.

 

On my webserver, I created a new directory called images

On my mysql database I created a new column called 'item_images' where I listed the URL path to the image needed for that record.

 

On my PHP page, what is the code to display the image?

 

Is it something like this?

IMG SRC="<?php echo $Item_Image.'.jpg'; ?>" WIDTH="100" HEIGHT="100" BORDER="0">

Link to comment
Share on other sites

Seems to me that you are not calling the image back from the database...

 

eg.

$result=mysql_query("select Item_Image from images");

$row=mysql_fetch_assoc($result);

$pic=$row[$Item_Image];

 

<img scr="<?=$pic?>" WIDTH="100" HEIGHT="100" BORDER="0">

 

I'm trying to modify some code from an existing PHP page.

which I believe has the row detail in it.

 

if ($query->recordcount() == 0)
	{
		echo "No items found! Try changing your search criteria.";
	}
	else
	{
		while ($item = $query->fetchrow())
		{
			echo "<fieldset>\n";
			echo "<legend><b>" . $item['name'] . "</b></legend>\n";
			echo "<table width=\"100%\">\n";
			echo "<tr><td width=\"85%\">";
			echo $item['description'] . "\n<br />";
			echo "<b>Effectiveness:</b> " . $item['effectiveness'] . "\n";
			echo "</td><td width=\"15%\">";
			echo "<b>Price:</b> " . $item['price'] . "<br />";
			echo "<a href=\"shop.php?act=buy&id=" . $item['id'] . "\">Buy</a><br />";
			echo "</td></tr>\n";
			echo "</table>";
			echo "</fieldset>\n<br />";

 

What I would like is to display the image right in front of the description.

 

Link to comment
Share on other sites

1. if Item_Image is called in  $query it should be available as <img scr="$item[item_Image]" WIDTH="100" HEIGHT="100" BORDER="0">

 

if you have created a new field in the table and the $query stipulates what field it wants then your new field will be missing and you will have to add it.

e.g. query=mysql_fetch_array('select record_number,etc,etc,etc from table'); you need to add Item_Image.

 

If the $query selects * then this is not the case so long as it is in the table in the first place

 

rather than display the image try echoing the variable to the screen e.g. echo $item[item_Image]; to see what it holds and if it is pointing to the correct directory.

 

Good luck

Link to comment
Share on other sites

1. if Item_Image is called in  $query it should be available as <img scr="$item[item_Image]" WIDTH="100" HEIGHT="100" BORDER="0">

 

if you have created a new field in the table and the $query stipulates what field it wants then your new field will be missing and you will have to add it.

e.g. query=mysql_fetch_array('select record_number,etc,etc,etc from table'); you need to add Item_Image.

 

If the $query selects * then this is not the case so long as it is in the table in the first place

 

rather than display the image try echoing the variable to the screen e.g. echo $item[item_Image]; to see what it holds and if it is pointing to the correct directory.

 

Good luck

 

I must be really close, I've added the new field to $query and did the echo, and it displayed the URL.

 

but if I do this

<img scr="$item[item_Image]" WIDTH="100" HEIGHT="100" BORDER="0">

 

I just get an error on the page.

 

should the code look like this?

			echo "<fieldset>\n";
			echo "<legend><b>" . $item['name'] . "</b></legend>\n";
			echo "<table width=\"100%\">\n";
			echo "<tr><td width=\"85%\">";
			<img scr="$item[item_Image]" WIDTH="100" HEIGHT="100" BORDER="0">;
			echo $item['description'] . "\n<br />";
			echo "<b>Effectiveness:</b> " . $item['effectiveness'] . "\n";
			echo "</td><td width=\"15%\">";
			echo "<b>Price:</b> " . $item['price'] . "<br />";
			echo "<a href=\"shop.php?act=buy&id=" . $item['id'] . "\">Buy</a><br />";
			echo "</td></tr>\n";
			echo "</table>";
			echo "</fieldset>\n<br />";

Link to comment
Share on other sites

good eye!

I fixed it, but it didn't make a difference.

 

<img src="$item['Item_Image']" WIDTH="100" HEIGHT="100" BORDER="0">;

 

 

the error I'm getting is

 

Parse error: syntax error, unexpected '<' in /home/caraudi/public_html/CAC_Mafia_Life/shop.php on line 194

 

line 194 the img line.

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.