Page 1 of 1
Using php to display 1-10, 11-20 results from a mysql query
Posted: Thu May 11, 2006 12:13 pm
by Citizen
Basically, i need to put the 1-10 results from a query in one html column adn 11-20 and so on in another column
What code do I use for this?
Posted: Thu May 11, 2006 12:45 pm
by Burrito
I'd suggest building an array with all of your results then using a for loop to limit the results per section.
Posted: Thu May 11, 2006 1:06 pm
by Citizen
Hmm... I know how to build an array and I know how to use a loop, but what do I do with the loop to get those results?
Posted: Thu May 11, 2006 1:31 pm
by Burrito
do your initial loop over the results with
while() to build your
array().
then use a
for() loop to loop over your specified number of results.
edit:
for your for loop you'd do something like this:
Code: Select all
for($i=0;$i<10;$i++)
echo $myArray[$i][$value];
Posted: Thu May 11, 2006 1:40 pm
by timvw
the trick is to search the web (or this forum) for 'pagination'.
pagination for all.
Posted: Thu May 11, 2006 1:56 pm
by RobertGonzalez
I'm not sure pagination is what the OP is looking for. It sounds like he wants to take X number of results and put them into a certain location in his markup. Then take another X number of the same result set and place them into a different location in his markup.
Code: Select all
<?php
$array_count = count($myarray);
echo '<table><tr><td>';
for ($i = 0; $i < $array_count; $i++) {
echo "This is the array value for iteration $i..." . $myarray[$i]['value'] . "<br />";
if ($i % 10) {
if ($i != $array_count - 1) {
echo '</td><td>';
}
}
}
echo '</td></tr></table>';
?>
I am sure there a ton of better ways to do this, but this might point you in a direction that could help.
PS The code above runs all of the results in the $myarray array through one long rowed table, with 10 results in each cell.