Jump to content

Query returning resource id # 7 ?


Glenskie

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.