grippat Posted October 18, 2007 Share Posted October 18, 2007 Is there a way to take the result from a MySQL query in PHP and split it up into several results? Say I have a result that contains 20,000 rows. Can I take that and divide it so that one variable holds rows 1 through 10,000 and the other holds rows 10,001 through 20,000? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 18, 2007 Share Posted October 18, 2007 There's not an automatic way to do it. You could use the LIMIT clause in the SQL query to only return a certain number of records, like this:SELECT ... FROM table LIMIT 10001, 10000that would get the next 10,000 records starting at record 10,001. Or, to do it yourself you could use something like this to get the first 10,000 in one array, and everything else (if there is) in a second array: $result = mysql_query(...);$n = 0;$set1 = array();$set2 = array();while ($n++ < 10000 && $row = mysql_fetch_assoc($result)) $set1[] = $row;while ($row = mysql_fetch_assoc($result)) $set2[] = $row; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.