Experts Round Table Network

Serverside Technology => PHP => Topic started by: seandelaney on January 29, 2007, 08:07:05 AM



Title: Pagination and Mod_rewrite
Post by: seandelaney on January 29, 2007, 08:07:05 AM
im using pagination for a set of query results.

the website now uses friendly URL's with the help from mod_rewrite.

im trying to get my pagination working again but in having trouble...

.htaccess file:

Code:
RewriteRule ^/results/page([0-9]{1,4})(/)$ results.php?num=$1 [L]

results.php file:

Code:
$query = "SELECT * FROM tblJobs";
$result = mysql_query($query) or die(mysql_error());
     
while($row = mysql_fetch_array($result))
{
     $data[] = $row;
     $i_Total++;
}
     
$params = array(
     'itemData' => $data,
     'perPage' => 5,
     'append' => false,
     'urlVar' => 'num',
     'mode' => 'Jumping',
     'path' => 'http://quest-recruiting/results/',
       'fileName' => 'page%d/'
);
     
$pager = & Pager::factory($params);
$pagedata = $pager->getPageData();
$links = $pager->getLinks();
   
foreach($pagedata as $row)
{
       // more code here
       $s_HtmlContent .= '<p>'.$row['description'].'</p>'."\n";
       // more code here
}

$s_HtmlContent .= '<p>Page: '.$links['all'].'</p>'."\n";

the example i was trying to follow to integrate my code with mod_rewrite was from this tutorial:

http://pear.php.net/manual/en/package.html.pager.intro.php (http://pear.php.net/manual/en/package.html.pager.intro.php)


Title: Re: Pagination and Mod_rewrite
Post by: VGR on January 29, 2007, 11:14:28 AM
personally, if I were you, I would save thousands of milliseconds not queryinf for "*" but for the limited subset corresponding to the page n

example if a page has 100 rows displayed :
select * from trucmuche ORDER BY... LIMIT 100*(n-1),100;

got it ? you will only query 100 rows, the exact contenance of your page.

I didn't read the rest, but this "jumped to my eyes" (translatation not guaranteed)


Title: Re: Pagination and Mod_rewrite
Post by: seandelaney on January 29, 2007, 11:42:22 AM
Sorry VGR, the "SELECT * FROM" was just for example.

however even for a simple query my pagination does not work if i try jumping to page 2 for example..


Title: Re: Pagination and Mod_rewrite
Post by: VGR on January 29, 2007, 11:59:07 AM
ok, so the not initialized counter and array $data are also for demo purposes, right ?

then sorry but I solved the problem myself in pure normal PHP for eee.org (and it works! Yes ma'm ;-), while you use a class that I don't know anything about.

personally, if by following the examples furnished with the class, I didn't suceed at least in a so basic task, I would drop the class and try an other one. And in last resort, having seen hundreds of lines of code that don't work as expected, I would rewrite/do it myself ;-)


Title: Re: Pagination and Mod_rewrite
Post by: VGR on January 29, 2007, 12:02:12 PM
side note : I never liked pear stuff. too much OO in there. black boxes. do it yourself or it's valueless.


Title: Re: Pagination and Mod_rewrite
Post by: seandelaney on January 29, 2007, 12:07:46 PM
Quote
ok, so the not initialized counter and array $data are also for demo purposes, right ?

not actually, just the SELECT query - i can modify my first comment with the real query if you want...?  The rest of the code is not example.

also eee.org redirects to http://www.uia.net/



Title: Re: Pagination and Mod_rewrite
Post by: VGR on January 29, 2007, 02:31:32 PM
yeah, some evil people took that acronym as a domain name ;-)

look my signature to know what is "the" eee.org