steviemac Posted October 4, 2007 Share Posted October 4, 2007 Hello, I want to be able to paginate my rows in two columns on one page i.e. Column 1 Column 2 row 0 row 5 row 1 row 6 row 2 row 7 row 3 row 8 row 4 row 9 <<Prev 12345 Next>> This is the code I use. I found it and on Google, tweaked it and it works great. <?php include 'dbmembers.php'; if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 30; $from = (($page * $max_results) - $max_results); $sql = mysql_query("SELECT * FROM table WHERE status='active' LIMIT $from, $max_results"); while($row = mysql_fetch_array($sql)){ echo "$row[last_name] $row[first_name] } $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM allmembers WHERE status='active'"),0); $total_pages = ceil($total_results / $max_results); echo "<p align=\"center\">Select a Page<br />"; if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">« Previous </a>"; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next »</a>"; } echo "</p>"; ?> Thanks in advance for any help. I have been working on this for a bout a week on and off with no success. Quote Link to comment https://forums.phpfreaks.com/topic/71745-pagination-in-two-columns-on-one-page/ Share on other sites More sharing options...
teng84 Posted October 4, 2007 Share Posted October 4, 2007 are you saying you wnat this Column 1 Column 2 row 0 row 5 row 1 row 6 row 2 row 7 row 3 row 8 row 4 row 9 instead of this <<Prev 12345 Next>> Quote Link to comment https://forums.phpfreaks.com/topic/71745-pagination-in-two-columns-on-one-page/#findComment-361304 Share on other sites More sharing options...
steviemac Posted October 4, 2007 Author Share Posted October 4, 2007 I want it to both. Page 1 would have two columns, 0-4 and 5-9 Page 2 would have 2 columns 9-14 and 15-19 and so on and so on until all the rows are displayed Quote Link to comment https://forums.phpfreaks.com/topic/71745-pagination-in-two-columns-on-one-page/#findComment-361307 Share on other sites More sharing options...
markjoe Posted October 4, 2007 Share Posted October 4, 2007 <?php $cols=2;$record=0; echo "<tr>"; while($row = mysql_fetch_array($sql)){ $record++; if($record>$cols){ echo "</tr><tr>"; $record=0; } echo "<td>$row[last_name] $row[first_name]</td>"; } echo "</tr>"; ?> The pagination is done by the query, so the column display is actually a seperate thing. I've done it before, but can't find the code. I think the code above is the right idea though. Quote Link to comment https://forums.phpfreaks.com/topic/71745-pagination-in-two-columns-on-one-page/#findComment-361312 Share on other sites More sharing options...
steviemac Posted October 4, 2007 Author Share Posted October 4, 2007 Can this even be done Quote Link to comment https://forums.phpfreaks.com/topic/71745-pagination-in-two-columns-on-one-page/#findComment-361324 Share on other sites More sharing options...
teng84 Posted October 4, 2007 Share Posted October 4, 2007 yes but it takes alot of process y? when you loop to have something like this 1 3 2 4 basically what you will get in normal process is 1 2 3 4 because of the <td> or <tr> if your going to table that so to obatain that i guess you have to hae a loop where in you will get those fist two and the secont 2 results. and you have to have another loop that will combine them something like get the first element wich is 1 and get the second elemnt which is 3 then combine then that how i see it i dont know if theres still better way Quote Link to comment https://forums.phpfreaks.com/topic/71745-pagination-in-two-columns-on-one-page/#findComment-361330 Share on other sites More sharing options...
steviemac Posted October 4, 2007 Author Share Posted October 4, 2007 OK thanks for your time. Quote Link to comment https://forums.phpfreaks.com/topic/71745-pagination-in-two-columns-on-one-page/#findComment-361332 Share on other sites More sharing options...
markjoe Posted October 4, 2007 Share Posted October 4, 2007 OK, sorry, i didn't pay enough attention. hmmmm, could you just put them in 2 tables? count the results - mysql_num_rows() round the number down - $col1 = floor(mysql_num_rows()) build single column table until $col1 number of records, then build 2nd table to the right with the remaining records. Just a quick brainstorm, does it make sense to anyone but me? Quote Link to comment https://forums.phpfreaks.com/topic/71745-pagination-in-two-columns-on-one-page/#findComment-361462 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.