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!
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}";
}
Re: Empty set but has a result