Results 1 to 3 of 3

Thread: Empty set but has a result

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    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

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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}";



  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Resolved Re: Empty set but has a result

    Thanks man.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width