Jump to content

Query returning resource id # 7 ?


Go to solution Solved by Psycho,

Recommended Posts

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);

 

Link to comment
https://forums.phpfreaks.com/topic/287495-query-returning-resource-id-7/
Share on other sites

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.

  • Solution

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 by Psycho
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.