Alright, I have an image url stored in a database for an ecommerce site. when someone goes to review an item, the image of the item is shown. but i can't get the image to show. so without further ado, here's my code:
function review_item()
{
global $review_item_id;
global $PHP_SELF;
global $browse_font_color;
$result=mysql_query("SELECT * FROM items WHERE item_id=$review_item_id");
WHILE ($row=mysql_fetch_array($result))
{
$item_name=$row["item_name"];
$item_description=$row["item_description"];
$item_price=$row["item_price"];
$image_id=$row["image_id"];
If ($image_id!='0'):
$result = mysql_query("SELECT * FROM `images` WHERE `image_id` = $image_id LIMIT 1;");
$row = mysql_fetch_row($result);
return($row[1]);
$blarg = getUrl(1);
Print "<img src=$blarg><BR>";
Endif;
Print "$item_name<BR>\n$item_description<BR>\n<BR>\n\$$item_price<BR><BR>";
Print "<a href='$PHP_SELF?buy_item_id=$review_item_id'>\n";
Print "<FONT FACE='Helvetica,Verdana,Arial' COLOR='#$browse_font_color'>";
Print "Purchase this Item";
Print "</FONT>";
Print "</a>\n";
}
}
with that code, nothing gets shown, image or the item stuff. can anyone suggest what i need to do? thanx.
Getting an image to display
Moderator: General Moderators
hmmm...
Next (you dont do
) is getting an url from the number 1 (always)
[looks like a copy&paste bug]
And then (worst of all because I like xml-style HTML
) you print an picture element having a property 'src' with a NOT QUOTED value and neither closing <img> nor <br> (just kidding, but it's much easier to 'debug')
the first thing you do (before any output is done) is return.return($row[1]);
$blarg = getUrl(1);
Print "<img src=$blarg><BR>";
Next (you dont do
[looks like a copy&paste bug]
And then (worst of all because I like xml-style HTML
When using PHP to call images, you cannot select the image from the actual page and insert it there. You still need to call out to another page, such as:
This would contact the getImage.php page, with parameters being sent to the page knows what image to return.
On this page, you simply do something like this:
Code: Select all
<img src="getImage.php?param1=1343¶m2=04u5">On this page, you simply do something like this:
Code: Select all
<?php
$sql = "SELECT image FROM image_tbl WHERE param1=1343 AND param2=04u5";
$result = mysql_query($sql);
list($image) = mysql_fetch_row($result);
header("Content-type: image/jpeg"); // image/gif or image/jpg
echo $image;
?>i used this, and it worked. thanx for the advice guys.
If ($image_id!='0'):
$query="SELECT image_url from images WHERE image_id='$review_item_id'";
$result=mysql_query($query);
$num_results=mysql_num_rows($result);
If ($num_results!=0):
$row=mysql_fetch_array($result);
$url=$row["image_url"];
echo "<img src=$url><BR>";
Else:
echo '<img src="http://www.3dmaxedout.com/na.jpg"></img>';
Endif;
//Print "<img src=$test_password><BR>";
Endif;
If ($image_id!='0'):
$query="SELECT image_url from images WHERE image_id='$review_item_id'";
$result=mysql_query($query);
$num_results=mysql_num_rows($result);
If ($num_results!=0):
$row=mysql_fetch_array($result);
$url=$row["image_url"];
echo "<img src=$url><BR>";
Else:
echo '<img src="http://www.3dmaxedout.com/na.jpg"></img>';
Endif;
//Print "<img src=$test_password><BR>";
Endif;