FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


how do I use pear pager with a mysql resultset





ammonkc
I've been trying to get the PEAR pager to work with no luck. How do I use the pear::pager package? or more specifically the pager_wrapper_db.php. the example.php that I found in the doc/examples/ works fine. but I can't get anything to work with a mysql resultset. below is what I've got so far, but doesn't seem to be working. I can get the links and the paging working but I cant get any of the data out of the resultset.

I can't really find any good examples online. any help would really be appreciated. thanks in advanced

Code:

<?php
require_once 'config.php';              //db connect variables
require('DB.php');
require 'Pager/Pager.php';
$dsn = $dbengine.'://'.
           $dbuser.':'.
           $dbpass.'@'.
            $dbhost.'/'.
             $dbname;

$db = DB::connect($dsn, TRUE);
if(DB::isError($db)) {
   die($db->getMessage());
}
$db->setFetchMode(DB_FETCHMODE_ASSOC);
$query = "select * from messages";
require_once 'Pager_Wrapper.php';
$pagerOptions = array(
    'mode'    => 'Sliding',
    'delta'   => 2,
    'perPage' => 10);
$paged_data = Pager_Wrapper_DB($db, $query, $pagerOptions);

echo '<html><body>';
//I don't know how to get the data from the resultset out of the $paged_data
echo 'total: '.$paged_data['page_numbers']['total'].'<br />'; //this works
echo 'current: '.$paged_data['page_numbers']['current'].'<br />';  //this works
echo $paged_data['links']; //this works
while ($row = $paged_data['data']->fetchRow()) {// This is where I don't know what to do to get the data out
   echo $row['msg_id'];
}

echo '</body></html>';
?>
ammonkc
I figured it out. I should've been using a foreach () instead of a while () loop.

Code:

<?php
require_once 'config.php';   //db connect variables
require('DB.php');
require 'Pager/Pager.php';
require_once 'Pager_Wrapper.php';
$dsn = $dbengine.'://'.
           $dbuser.':'.
           $dbpass.'@'.
            $dbhost.'/'.
             $dbname;

$db = DB::connect($dsn, TRUE);
if(DB::isError($db)) {
   die($db->getMessage());
}
$query = "select * from messages";
$pagerOptions = array(
    'mode'    => 'Sliding',
    'delta'   => 2,
    'perPage' => 20);
$paged_data = Pager_Wrapper_DB($db, $query, $pagerOptions);

echo '<html><body>';
echo 'total: '.$paged_data['page_numbers']['total'].'<br />'; //this works
echo 'current: '.$paged_data['page_numbers']['current'].'<br />';  //this works
echo $paged_data['links'].'<br />'; //this works
foreach ($paged_data['data'] as $row){
   echo $row['msg_id'].'<br />';
}//end foreach
echo '</body></html>';
?>
Related topics
mysql connection question
php admin and mysql admin console
Mysql And PHP HELP PLZ
Do you use a CMS script?
Question about MySQL!
XAMPP - All-in-One WebServer package
PHP, MySQL...
Need some php/mysql dlls
php 5 PEAR installation
How to set up PEAR with my php5
Limit results/page
need help: Call to undefined function error
Apache server with php???
Newbie PHP/MySQL question
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.