Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PHP] Display Records in Multiple Pages help please !

0 views
Skip to first unread message

dan...@electroteque.org

unread,
Aug 4, 2003, 9:38:31 PM8/4/03
to jus...@indent.com.au, david....@citigroup.com, php-g...@lists.php.net
a sample from my db class, i had to store the total in a session as calling
the total on every page on a large database was painful doing count(*) or
even SQL_CALC_FOUND_ROWS, on a small database u just cant tell but on a
database of 100k + it was painful to load each page ;)

function page_query($per_page, $query, $page, $session_var, $debug = null,
$start_session = null) {
if ($start_session) session_start();
if(!$page) {
$this->page = 1;
$this->start = 0;
} else {
$this->page = $page;
$this->start = ($this->page - 1) * $per_page;
}

if ((!$page && !$_SESSION[''.$session_var.'']) || (!
$_SESSION[''.$session_var.''])) {
$query = preg_replace("/SELECT|select/","\\0
SQL_CALC_FOUND_ROWS",$query);
$query = "$query LIMIT $this->start, $per_page";
$result = $this->query($query);
if ($debug) $this->debug();
$row = $this->getOne("SELECT FOUND_ROWS() as
total_rows");
$_SESSION[''.$session_var.''] = $row['total_rows'];
$this->total = $_SESSION[''.$session_var.''];
} else {
$query = "$query LIMIT $this->start, $per_page";
$result = $this->query($query);
if ($debug) $this->debug();
$this->total = $_SESSION[''.$session_var.''];
}
$this->pages = ceil($this->total / $per_page);
return $result;
}

Justin French

unread,
Aug 4, 2003, 9:05:35 PM8/4/03
to Coello, David, php
Well, you haven't told us what database you're using at all, but I'll
assume MySQL. In which case you should look at the LIMIT part of your
query.

http://www.mysql.com/doc/en/SELECT.html

All you need to do is pass around a starting point variable on each
page, so that you know where the result for the next page of results
will start from (eg row 40 or 41 for page 3)

Justin


On Tuesday, August 5, 2003, at 02:53 AM, Coello, David wrote:

> good afternoon i found a forum about displaying 25 records per page,
> im using cgi and i need also to display only 25 records per page but i
> want to be able to go to my next page and see the next 25 and so on...
> the proble that im having is that i have a about 2000 records and the
> query that i use calls all of them? how do i limit them
> thank you david coello
>
> David Coello
> david....@citigroup.com
> phone: 212-657-1649
> Fax: 212-657-7517
>
> ---
> [This E-mail scanned for viruses]
>
>

dan...@electroteque.org

unread,
Aug 4, 2003, 9:44:00 PM8/4/03
to dan...@electroteque.org, jus...@indent.com.au, david....@citigroup.com, php-g...@lists.php.net
100k = 100k records = 200 meg hehe
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

Justin French

unread,
Aug 5, 2003, 9:06:09 AM8/5/03
to Coello, David, php
If you're using CGI/Perl, WHY WHY WHY are you asking questions on a PHP
list?

I've given you a hint, so perhaps take that hint and ask a question on
an Oracle list, or search the Oracle documentation for similar
functions.

Justin French


On Tuesday, August 5, 2003, at 10:37 PM, Coello, David wrote:

> thank you for replying, good morning.
> im using oracle 8. with cgi/perl
> thank you david


>
> -----Original Message-----
> From: Justin French [mailto:jus...@indent.com.au]
>
> Well, you haven't told us what database you're using at all, but I'll
> assume MySQL. In which case you should look at the LIMIT part of your
> query.
>
> http://www.mysql.com/doc/en/SELECT.html
>
> All you need to do is pass around a starting point variable on each
> page, so that you know where the result for the next page of results
> will start from (eg row 40 or 41 for page 3)
>

0 new messages