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?
Using php to display 1-10, 11-20 results from a mysql query
Moderator: General Moderators
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:
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];- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.
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.
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>';
?>PS The code above runs all of the results in the $myarray array through one long rowed table, with 10 results in each cell.