So I have this problem with php/mySql. I have the code shown below, and somehow it doesn't echo my the image (which is what is stored in the cell selected), but when I execute the exact same query in phpMyAdmin it suddenly works!
<?php
$logo_query = mysql_query("SELECT 'img_thumb_url' FROM rederijen WHERE id = '13';");
//echo '<img src="' .$logo_query. '">';
echo $logo_query;
?>
Instead of echoing me the URL to the image (lets just say it's "http://www.example.com/img/foo.jpg"), it returns me this:
Resource id #18
just as plain text.
Any help would be greatly appreciated.
That's because you're trying to echo out a resource. What you're wanting to do is echo out the result, which you can do by first calling mysql_fetch_row
:
<?php
$logo_query = mysql_query("SELECT `img_thumb_url` FROM rederijen WHERE id = '13';");
$row = mysql_fetch_row($logo_query);
// you now have the result in an array, so to echo out 'img_thumb_url' we'll echo out the first key in the array
echo $row[0];
?>
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. www.php.net/mysql_query
You should try:
while ($row = mysql_fetch_assoc($logo_query)) {
echo $row['img_thumb_url'];
}
Of course you should read more about mysql extension, and maybe switch to mysqli or PDO.