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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
online
Forum Newbie
Posts: 8
Joined: Thu Sep 01, 2005 7:48 am

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

Post 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]
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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
online
Forum Newbie
Posts: 8
Joined: Thu Sep 01, 2005 7:48 am

Post by online »

Ok.. I find a lot of tutorials and scripts with pagination..

But how to integrate with the code?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
Post Reply