cdoyle Posted February 13, 2008 Share Posted February 13, 2008 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 https://forums.phpfreaks.com/topic/90828-display-an-image-from-server/ Share on other sites More sharing options...
Riparian Posted February 13, 2008 Share Posted February 13, 2008 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"> Link to comment https://forums.phpfreaks.com/topic/90828-display-an-image-from-server/#findComment-465522 Share on other sites More sharing options...
cdoyle Posted February 13, 2008 Author Share Posted February 13, 2008 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 https://forums.phpfreaks.com/topic/90828-display-an-image-from-server/#findComment-465528 Share on other sites More sharing options...
Riparian Posted February 13, 2008 Share Posted February 13, 2008 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 https://forums.phpfreaks.com/topic/90828-display-an-image-from-server/#findComment-465541 Share on other sites More sharing options...
cdoyle Posted February 13, 2008 Author Share Posted February 13, 2008 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 https://forums.phpfreaks.com/topic/90828-display-an-image-from-server/#findComment-465576 Share on other sites More sharing options...
digitalmartyr Posted February 13, 2008 Share Posted February 13, 2008 try checking your spelling in the img src, you have it as scr.... thats gonna be the issue. its not the php its the html. Chad Link to comment https://forums.phpfreaks.com/topic/90828-display-an-image-from-server/#findComment-465583 Share on other sites More sharing options...
cdoyle Posted February 13, 2008 Author Share Posted February 13, 2008 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 https://forums.phpfreaks.com/topic/90828-display-an-image-from-server/#findComment-465621 Share on other sites More sharing options...
cdoyle Posted February 13, 2008 Author Share Posted February 13, 2008 anybody else see something I'm missing? Link to comment https://forums.phpfreaks.com/topic/90828-display-an-image-from-server/#findComment-466344 Share on other sites More sharing options...
cdoyle Posted February 14, 2008 Author Share Posted February 14, 2008 If anyone later on needs to know the answer, it's echo "<img src=\"" . $item['Item_Image'] . "\"/>"; Link to comment https://forums.phpfreaks.com/topic/90828-display-an-image-from-server/#findComment-466447 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.