[PHP] how to determine if a mysql query returns an empty set?

2009-04-23 Thread Adam Williams
Is there a way to determine if a mysql query returns an empty set?  I am 
selecting 10 results at a time with a limit statement and need to know 
when i've ran out of rows.  I've only got 2 rows in the database, so 
when I start with row 10, it returns an empty set.  I have the following 
code:


//running this query gives Empty set (0.00 sec) in mysql console.

$get_requests = select form_id, full_name, email, phone, division, 
location, date_format(time_of_request, '%m-%d-%Y %r') as 
time_of_request, contact_time, problem, accepted_by, 
date_format(accepted_time, '%m-%d-%Y %r') as accepted_time, resolution, 
date_format(resolution_time, '%m-%d-%Y %r') as resolution_time from form 
where ((stage = 'Closed')  (email = 'awilliam' )) order by 
resolution_time limit 10 , 10


//checks to see if it returns nothing, then print that you are at the 
end of the results


   if (!$mysqli_get_requests = 
mysqli_query($mysqli,$get_requests))

   {
   echo You have reached the end of the results.
   Please press the back button.
   form action=/helpdesk/login.php method=postinput
   type=submit value=Back
   name=submit/form/body/html;
   exit;
   }

but that doesn't work, because I guess an empty set is not false, 0, or 
NULL?





Re: [PHP] how to determine if a mysql query returns an empty set?

2009-04-23 Thread Nitsan Bin-Nun
mysql_num_rows() maybe? if not I probably haven't understood your question.

On Thu, Apr 23, 2009 at 8:12 PM, Adam Williams awill...@mdah.state.ms.uswrote:

 Is there a way to determine if a mysql query returns an empty set?  I am
 selecting 10 results at a time with a limit statement and need to know when
 i've ran out of rows.  I've only got 2 rows in the database, so when I start
 with row 10, it returns an empty set.  I have the following code:

 //running this query gives Empty set (0.00 sec) in mysql console.

 $get_requests = select form_id, full_name, email, phone, division,
 location, date_format(time_of_request, '%m-%d-%Y %r') as time_of_request,
 contact_time, problem, accepted_by, date_format(accepted_time, '%m-%d-%Y
 %r') as accepted_time, resolution, date_format(resolution_time, '%m-%d-%Y
 %r') as resolution_time from form where ((stage = 'Closed')  (email =
 'awilliam' )) order by resolution_time limit 10 , 10

 //checks to see if it returns nothing, then print that you are at the end
 of the results

   if (!$mysqli_get_requests =
 mysqli_query($mysqli,$get_requests))
   {
   echo You have reached the end of the results.
   Please press the back button.
   form action=/helpdesk/login.php method=postinput
   type=submit value=Back
   name=submit/form/body/html;
   exit;
   }

 but that doesn't work, because I guess an empty set is not false, 0, or
 NULL?





Re: [PHP] how to determine if a mysql query returns an empty set?

2009-04-23 Thread Andrew Ballard
On Thu, Apr 23, 2009 at 2:12 PM, Adam Williams
awill...@mdah.state.ms.us wrote:
 Is there a way to determine if a mysql query returns an empty set?  I am
 selecting 10 results at a time with a limit statement and need to know when
 i've ran out of rows.  I've only got 2 rows in the database, so when I start
 with row 10, it returns an empty set.  I have the following code:

 //running this query gives Empty set (0.00 sec) in mysql console.

 $get_requests = select form_id, full_name, email, phone, division,
 location, date_format(time_of_request, '%m-%d-%Y %r') as time_of_request,
 contact_time, problem, accepted_by, date_format(accepted_time, '%m-%d-%Y
 %r') as accepted_time, resolution, date_format(resolution_time, '%m-%d-%Y
 %r') as resolution_time from form where ((stage = 'Closed')  (email =
 'awilliam' )) order by resolution_time limit 10 , 10

 //checks to see if it returns nothing, then print that you are at the end of
 the results

               if (!$mysqli_get_requests =
 mysqli_query($mysqli,$get_requests))
                       {
                       echo You have reached the end of the results.
                       Please press the back button.
                       form action=/helpdesk/login.php method=postinput
                       type=submit value=Back
                       name=submit/form/body/html;
                       exit;
                               }

 but that doesn't work, because I guess an empty set is not false, 0, or
 NULL?




It won't be any of those because the query is successful even if it
returns no records. You could use
http://us2.php.net/manual/en/mysqli-stmt.num-rows.php to determine how
many rows were returned.

Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] how to determine if a mysql query returns an empty set?

2009-04-23 Thread Adam Williams



Nitsan Bin-Nun wrote:

mysql_num_rows() maybe? if not I probably haven't understood your question.


  

Thanks, I never thought of trying that.  This code works!

   $mysqli_get_requests = mysqli_query($mysqli,$get_requests);
   if (!mysqli_num_rows($mysqli_get_requests))
   {
   echo You have reached the end of the results.
   Please press the back button.
   form action=/helpdesk/login.php method=postinput
   type=submit value=Back
   name=submit/form/body/html;
   exit;
   }



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] how to determine if a mysql query returns an empty set?

2009-04-23 Thread Adam Williams



Andrew Ballard wrote:

It won't be any of those because the query is successful even if it
returns no records. You could use
http://us2.php.net/manual/en/mysqli-stmt.num-rows.php to determine how
many rows were returned.

Andrew
  

Oh ok, thanks that makes sense.  Thanks for the link also


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php