oriental_express Posted April 26, 2011 Share Posted April 26, 2011 Hi there I've been working with some code to display a single record on page. This all works fine and I'm able to pull what I want from the database. My problems is trying to use that data and turning it into something else like a link. I have a field in the database called image url which contains rows of image urls. So here is the problem area of the code: <?php //////Displaying Data///////////// $id=$_GET['id']; // Collecting data from query string if(!is_numeric($id)){ // Checking data it is a number or not echo "Data Error"; exit; } $fetch=mysql_query("select * from productfeeds where ProductID=$id "); $row=mysql_fetch_object($fetch); echo mysql_error(); echo "<table>"; echo " <tr><td><b>ProductID</b></td><td>$row->ProductID</td></tr> <tr><td><b>ProductName</b></td><td>$row->ProductName</td></tr> <tr><td><b>ProductPrice</b></td><td>$row->ProductPrice</td></tr> //problem area for me <tr><td><b>Image</b></td><td>$row->ImageURL</td></tr> echo "</table>"; I'm trying to edit this part of the code: <tr><td><b>Image</b></td><td>$row->ImageURL</td></tr> I've tried this: <tr><td><b>Image</b></td><td><a href='{$row['URL']}'> <img src='{$row['ImageURL']}'></a> and <tr><td><b>Image</b></td><td><a href='$row['URL']'> <img src='$row['ImageURL']'></a> //removed brackets but I'm just getting errors. Can you guys help please? Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/234753-creating-image-links-from-database/ Share on other sites More sharing options...
fugix Posted April 26, 2011 Share Posted April 26, 2011 what errors are you receiving? and what exactly do you have stored for your image urls inside of your db? Quote Link to comment https://forums.phpfreaks.com/topic/234753-creating-image-links-from-database/#findComment-1206408 Share on other sites More sharing options...
Muddy_Funster Posted April 26, 2011 Share Posted April 26, 2011 The code you have looks like it should work as is, you will need to assign the elements ( bit after the ->) to variables if you want to do things the way you are trying (so $img_url = $row->ImageURL), or change the mysql_fetch_object() to mysql_fetch_assoc() and use a while loop to run through the values. if you just want to use the current code in the href this should work: <tr><td><b>Image</b></td><td><a href='{$row->ImageURL}'> <img src='{$row->ImageURL}'></a> assuming that you want to link to the image, but I don't see any other refference to a URL that you want to follow. Quote Link to comment https://forums.phpfreaks.com/topic/234753-creating-image-links-from-database/#findComment-1206417 Share on other sites More sharing options...
oriental_express Posted April 26, 2011 Author Share Posted April 26, 2011 Hi there and thanks for reply: If is try this: <tr><td><b>Image</b></td><td><a href='{$row['URL']}'> <img src='{$row['ImageURL']}'></a> the error is returned as this: ( ! ) Fatal error: Cannot use object of type stdClass as array in C:\wamp\www\Test\product.php on line 28 Call Stack # Time Memory Function Location 1 0.0032 374216 {main}( ) ..\product.php:0 If is try this: <tr><td><b>Image</b></td><td><a href='$row['URL']'> <img src='$row['ImageURL']'></a> //removed brackets the error is returned as this: ( ! ) Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\Test\product.php on line 28 Inside the database I have a column called ImageURL and its just urls of the image path (external url) Basically I want to hyper link that image with a url to wherever I want to point it. Does this help in any way? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/234753-creating-image-links-from-database/#findComment-1206419 Share on other sites More sharing options...
oriental_express Posted April 26, 2011 Author Share Posted April 26, 2011 The code you have looks like it should work as is, you will need to assign the elements ( bit after the ->) to variables if you want to do things the way you are trying (so $img_url = $row->ImageURL), or change the mysql_fetch_object() to mysql_fetch_assoc() and use a while loop to run through the values. if you just want to use the current code in the href this should work: <tr><td><b>Image</b></td><td><a href='{$row->ImageURL}'> <img src='{$row->ImageURL}'></a> assuming that you want to link to the image, but I don't see any other refference to a URL that you want to follow. Once again you have helped me solve my problem Quote Link to comment https://forums.phpfreaks.com/topic/234753-creating-image-links-from-database/#findComment-1206421 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.