Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/71745-pagination-in-two-columns-on-one-page/
Share on other sites

<?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.

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

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.