Page 1 of 1

Php - Next Prev pages (to add to this code)

Posted: Sat Nov 19, 2005 4:02 pm
by online
Sami | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hello!
I have this code:

Code: Select all

<?php
$columns = 3;

mysql_connect('localhost','','');
mysql_select_db('');

//change the query to get another field from the database
$query = "SELECT * FROM terms ORDER BY termID";
$result = mysql_query($query);

$num_rows = mysql_num_rows($result);


$rows = ceil($num_rows / $columns);

while($row = mysql_fetch_array($result)) {
    $data[] = $row['termID'];

    //store the other field into an array
    $data2[] = $row['keyword'];
}

echo "<TABLE BORDER=\"0\">\n";

for($i = 0; $i < $rows; $i++) {

    echo "<TR>\n";

    for($j = 0; $j < $columns; $j++) {
        if(isset($data[$i + ($j * $rows)])) {
            echo "<TD>" . $data[$i + ($j * $rows)] . "</TD>\n";

            //echo out the field
            echo "<TD>" . $data2[$i + ($j * $rows)] . "&nbsp;</TD>\n";
        }
    }
    echo "</TR>\n";
}
echo "</TABLE>\n";
?>
This code it display me the terms from my sql... 3 columns...
But the problem is that it display me all data into a page!

And i have 200.000 records!

I want to view only 50 records/page (in column style) ..and to generate link..prev.. (1 2 3 ..... next)!

So..who could help me?

Thanks in advance!


Sami | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sat Nov 19, 2005 4:13 pm
by m3mn0n
So you need pagination, eh?

Check out this tutorial: http://www.phpfreaks.com/tutorials/43/0.php

d11wtq | And also check out Jcart's Pagination Class in Code Snippets

Posted: Sat Nov 19, 2005 4:16 pm
by online
Ok.. I find a lot of tutorials and scripts with pagination..

But how to integrate with the code?

Posted: Sat Nov 19, 2005 4:20 pm
by m3mn0n
Read through a good one, understand the process, and maybe do it with their sample code. And once you understand the process, it shouldn't be hard to modify your script to accommodate your pagination needs.