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"> Quote Link to comment 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"> Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 />"; Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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'] . "\"/>"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.