|
-
Apr 14th, 2010, 07:36 PM
#1
Thread Starter
Fanatic Member
Empty set but has a result
I have a weird problem. The query seems to be empty but I got a result resource.
Code:
$query = 'SELECT ...';
print_r($this->db . '<br>');
$result = mysql_query($query, $this->db);
print_r($result);
if ($result) {
$price_max_schedules = mysql_result($result, 0, "value");
}
Outputs:
Code:
Resource id #72
Resource id #97
I know I'm missing something but I can't seem to find it. Help anyone? Thanks in advance!
Last edited by nebulom; Apr 14th, 2010 at 07:39 PM.
Reason: Added output
-
Apr 14th, 2010, 10:04 PM
#2
Re: Empty set but has a result
remember that mysql_query() returns a resource on a successful SELECT statement, or false on an error. that doesn't mean something is actually being returned, though -- it just means that the query was successfully executed. then, you're trying to print_r() to resources ($this->db and $result) and because of that you're getting the resource IDs echoed out. you'll need to check mysql_num_rows() to see if a result was actually returned. I'd also suggest using something like mysql_fetch_assoc() if you'd like an easier way of returning values from your result.
a quick example of using mysql_num_rows() and mysql_fetch_assoc():
PHP Code:
$sql = "SELECT field1, field2 FROM table"; $result = mysql_query($sql);
//check if a row was returned if(mysql_num_rows($result) > 0){
$row = mysql_fetch_assoc($result);
print_r($row);
}else{
echo "no results for {$sql}";
}
-
Apr 15th, 2010, 01:09 PM
#3
Thread Starter
Fanatic Member
Re: Empty set but has a result
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|