|
|
 Steve Jennings - 2008-09-18 14:18:05
I have a php program that fetches data from an SQL data base and if the user selects all records there can be up to 14,000 so I am trying to use this class to help. But I cant figure out how to use it.
Thanks
 Seregwethrin - 2008-09-18 15:49:02 - In reply to message 1 from Steve Jennings
Hello Mr. Jennings;
Firstly, you need records counts for paging. Let me show you with an example:
For example we are at a forum and it's topic. there's 400 posts. You want to show 10 posts per page. Firstly you need to get that "400" count from database. You can get it like this
$count = mysql_query("SELECT COUNT(*) FROM posts WHERE topic_id='$topic_id'");
$count = mysql_fetch_array ( $count );
$count = array_pop ( $count ); //we are doing this because count is returned as $count['COUNT(*)']
And than include the class
include ( 'paging.class.php' );
$paging = new paging; //make the class' object
$paging->assign ( "topic.php?id=$topic_id&" , $count , 10 );
after need to get your sql limit code
$sql_limit = $paging->sql_limit();
Than get your posts
$posts = mysql_query("SELECT * FROM posts WHERE topic_id='$topic_id' LIMIT $sql_limit");
while ( $post = mysql_fetch_array ( $posts ) )
{
echo $post['id'] . $post['poster'];
.
.
.
}
It's easy to paging results with this class :)
 Seregwethrin - 2008-09-18 15:55:43 - In reply to message 2 from Seregwethrin
I forgot, also at the end you can write page listings with this
echo $paging->fetch();
that's all :)
just you need
include ( 'paging.class.php' );
$paging = new paging;
$paging->assign ( URL, total records, records per page );
$sql_limit = $paging->sql_limit();
for getting rows. Like if you are at third page and if you want to display 20 records per page, sql limit will return 40,20. LIMIT 40,20 means start at 40. records and get 20 records after it.
and also writing pages
echo $paging->fetch();
 Steve Jennings - 2008-09-18 18:55:48 - In reply to message 3 from Seregwethrin
Ok, now it's clear . . . I had not thought about first obtaining the number of records I would be dealing with . . .I have multiple queries in my app and each query would require a separate query to determine the number of records
Thanks very much for your response . . . and your code.
Steve
 Seregwethrin - 2008-09-19 21:20:26 - In reply to message 4 from Steve Jennings
Good works with the perfect paging Mr.Jennings
 Pradeep - 2009-05-27 11:37:33 - In reply to message 5 from Seregwethrin
HI,
Note sure why, but we are getting this error when running your class.
Notice: Undefined index: page in D:\wamp\www\chamong\paging.class.php on line 148
1CONSIGNMENT2Export3Export4Export6LOCAL7CONSIGNMENT8Export9CONSIGNMENT FROM GARDEN
Notice: Undefined property: paging::$html in D:\wamp\www\chamong\paging.class.php on line 187
Notice: Undefined property: paging::$page_back in D:\wamp\www\chamong\paging.class.php on line 328
Notice: Undefined property: paging::$page_first in D:\wamp\www\chamong\paging.class.php on line 328
Notice: Undefined property: paging::$page_last in D:\wamp\www\chamong\paging.class.php on line 328
Notice: Undefined property: paging::$page_fwd in D:\wamp\www\chamong\paging.class.php on line 328
1
Any idea, this is due to the server setting or wat. i am using WAMP server with php5 localyy.
Thanks
|