Glenskie Posted April 3, 2014 Share Posted April 3, 2014 I am running this query and the only thing i want is the title and for some reason it is giving me this. Recourse id # 7 ? Here is my query that i am running. $photo = $_GET['image']; $retrievetitle = "SELECT title FROM photo_from_user WHERE picture = '$photo' limit 1"; $title = mysql_query($retrievetitle); Quote Link to comment https://forums.phpfreaks.com/topic/287495-query-returning-resource-id-7/ Share on other sites More sharing options...
gristoi Posted April 3, 2014 Share Posted April 3, 2014 mysql_query returns a resource, you need to loop through that resource to get the data back. Quote Link to comment https://forums.phpfreaks.com/topic/287495-query-returning-resource-id-7/#findComment-1474829 Share on other sites More sharing options...
ginerjm Posted April 3, 2014 Share Posted April 3, 2014 To finish your (deprecated) code: if ($title) { $row = MySQL_fetch_assoc($title); $my_title = $row['title']; } else { echo "Error running title query - message is " . MySQL_error(); exit(); } Of course you should change your db interface to mysqlI or pdo to keep up with the times. Quote Link to comment https://forums.phpfreaks.com/topic/287495-query-returning-resource-id-7/#findComment-1474830 Share on other sites More sharing options...
Solution Psycho Posted April 3, 2014 Solution Share Posted April 3, 2014 (edited) Or more simply use mysql_result(). I've renamed the variables to more commonly used for the intended purpose. There's no need to give all the query strings or the results unique names: $photo = mysql_real_escape_string(trim($_GET['image'])); $query = "SELECT title FROM photo_from_user WHERE picture = '$photo' limit 1"; $result = mysql_query($query); if(!$result) { echo "Error running title query - message is " . mysql_error(); exit(); } $title = mysql_result($result, 0); Edited April 3, 2014 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/287495-query-returning-resource-id-7/#findComment-1474833 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.