Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
I'm going to be making a generic pagination class, but was wondering how would be best to pass (or process in the class) the amount of results that have been found.
Basically, do you have to perform 2 queries - one to get how many results are possible and one to LIMIT the results? Or is there a way to combine them into one query, perhaps using a JOIN or some such?
There's two options... do two queries, one to find out the total results and another to fetch the limited recordset. That method is more memory efficient but it does require 2 queries. The other method is to fetch the entire recordset and then seek (with mysql_data_seek() if you're using a vanilla mysql connection) to the right place to start. That uses more memory but it's a little faster in most circumstances because it's only a single query.
I've been buried in JavaScript for about the last month, but one of the features I've used several times is the length function applied to an array to get the number of items in the array. PHP's equivalent is the sizeof($array) function. Might you be able to use that with a single query if the results array fetched is of the BOTH type? You could possibly eliminate COUNT altogether that way.
Last edited by VirtuosiMedia on Thu Sep 25, 2008 2:48 pm, edited 1 time in total.