mysql
Rob asked:


I’m fetching results form a MySQL query using PHP. In my while loop I’m using a switch statement to execute blocks of code based on the results of a certain field type. After I have retrieved all the results for based on a certain field, I need to execute one last bit of code. Is their a way to tell if the row returned by the MySQL query is the last row matching a certain field? I figure it would be best to use an if statement to test if the result is the last row matching a certain field and execute my remaining code. Any other suggestions?

Comments

Colinc on 21 April, 2008 at 11:44 am #

Just set your code to run the final closing routine after the loop finishes, this will need you to set variables for the record data if you want to be able to use the final data outside the loop, but if not it is very simple. A simple section in the loop could also set a variable like $if_found to 1 if any data is found, initialise it to 0 before the loop. Use an if on this to control whether the final routine runs.


Jacob P on 24 April, 2008 at 1:10 am #

You can use mysql_num_rows to get the number of results a query returns, and work with that:


Post a Comment
Name:
Email:
Website:
Comments: