PEAR Packages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPEAR Packages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old July 24th, 2005, 04:21 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
Need HELP with paging.

Hi there!
I finally managed to do paging BUT it works only when i manually give 'category' a value.
If i use $_POST[category] only the first page can be seen.
Here is my code.
<?php include("header.php"); php?>

<?php
require_once 'Pager.php';
$db = DB::connect('mysql://root:@localhost/db');

$sql = "SELECT title,year
FROM document AS doc
WHERE year between 1995 and 2005
AND category='$_POST[category]'";
// Find our starting Row
$from = $_GET['from'];
if (!is_numeric($from)){
$from = 0; }
// We'll limit the rows to 10 per page
$limit = 2;

// Get the total number of rows and build our pager
$nrows =& $db->getRow('SELECT count(*)
FROM document AS doc
WHERE year between 1995 AND 2005
AND category='$_POST['category']');
$data = DB_Pager::getData($from, $limit, $nrows[0]);


// Grab 2 rows using PEAR:B limitQuery function
$res = $db->limitQuery($sql, $from, $limit);
// Display the rows
print("<p><HR width=100% size=4 noshade><p>");

// Build our pager
echo $data['numrows'] . ' Results found -- ';
echo 'displaying '. $data['limit'] . ' results per page<br><br>';

// Create a header showing which page we're on
echo '<h4> Page '. $data['current'] . ' of ' . $data['numpages'] . '</h4>';

print("<p><TABLE border=1>n");
print("<TR><TD><center><b>year</b></center></TD>
<TD><b><center>title</center></b>
</TR>");
while ($row = $res->fetchRow()) {
print("<TR ALIGN=LEFT VALIGN=TOP>");
print("<TD>$row[2]</TD>");
print("<TD>$row[1]</TD>");
}
print("</TR></TABLE><p>");

//echo "Jump to page: ";
// Unless we're on the first page, show a link to the previous page
if ($data['current'] != $data['firstpage']){
echo '<a href="'. "$PHP_SELF?from=" . $data['prev'] .'"><< Prev </a>';
}
// Direct link to pages
foreach ($data['pages'] as $page => $start_row) {
echo "[ <a href='$PHP_SELF?from=$start_row'>$page</a> ] ";
}
// Unless we're on the last page, show a link to the next page
if ($data['current'] != $data['lastpage']){
echo '<a href="'. "$PHP_SELF?from=" . $data['next'] . '">Next>> </a>';
}
?>
<?php include("footer.php"); php?>
Thanks.

Reply With Quote
  #2  
Old July 24th, 2005, 09:53 PM
lig's Avatar
lig lig is offline
"Forum Nazi"
Codewalkers Demi-God (4500 - 4999 posts)
 
Join Date: Apr 2007
Location: Jacksonville, Fl
Posts: 4,721 lig User rank is Private First Class (20 - 50 Reputation Level)lig User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 26 m 5 sec
Reputation Power: 6
RE: Need HELP with paging.

How is this related to PEAR?

Reply With Quote
  #3  
Old July 25th, 2005, 11:13 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Need HELP with paging.

Well! It is not! I've just seen I was at wrong place. Anyway I'll try to post it somewhere else.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPEAR Packages > Need HELP with paging.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway