Jump to content

Help with SMARTY + PEAR Pager


whit3fir3

Recommended Posts

I have a site that I am working on and I have run into a bit of an issue.  In short the problem I am having is I can not get SMARTY and PEAR Pager package to work well together.  What happens is I browse to the page in questions.  I have Pager set to display 10 records from my database per page.  I see my 10 records and everything appears to be working.  As soon as I click the link for the "NEXT Page" or any page other than the first page it displays the page with no data from my database. 

 

The part that I find really odd about this is in my display template I am using SMARTY's "cycle" function to alternate row colors.  When I display a page other than the first I get just I get no database data back, but I do get 10 blank rows with alternating colors.  I am using Eclipse PDT to develop the and I have already been through the debugger.  The PEAR Pager is correctly getting the next 10 records when the "Next Page" link is selected, but it appears like SMARTY is just not displaying them.

 

I am currently using PHP 5.2.9 with Apache 2.2.11.  For PEAR Pager I am using version 2.4.8 and for Smarty I am using 3.0b2.  While this is a beta version of SMARTY everything I have read about it says that it is stable.  Lastly I have my Apache logs set to debug, and when I view the error.log after visiting the page and clicking the "Next Page" link I get no new entries in the error.log.

 

I am hoping that some one else has run into this same problem and can point me in the right direction.  If not I am open to other data paging solutions besides the PEAR Pager if anyone knows of a decent one.

 

Thanks,

 

Whit3fir3

Link to comment
https://forums.phpfreaks.com/topic/181792-help-with-smarty-pear-pager/
Share on other sites

I am not sure why I did not think of this before, but it might help if I posted the code to the page that I am having problems with...

 

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
##############Check if user is logged in
//session_start();
//if ($_SESSION['isLoggedIn'] != true){
//	header('Location: login.php');
//	exit;
//}
########################################
###########This is to include site title 
$titleFile = '../includes/sitename.txt';
$fh = fopen($titleFile, 'r');
$title = fgets($fh);
fclose($fh);
########################################
require_once '../../libs/Smarty.class.php';
require_once 'Pager.php';
require_once 'Pager/Sliding.php';
require_once '../Connections/DBConn.php';



//$smarty->compile_check = true;
//$smarty->debugging = false;
//$smarty->caching = false;

$sql = "SELECT t1.id as 'id',t3.name as 'brand',t2.Name as 'sport',t1.fname,t1.lname,
t1.cardnum,t1.year1,t1.year2,t1.price,t1.qty,t4.cond as 'cond',t1.img, t1.beckett_price,
t1.price_paid as 'paid' FROM `cards` 
as t1 INNER JOIN `sports` as t2 on t2.id=t1.sportID INNER JOIN `brand` 
as t3 on t3.id=t1.brandID INNER JOIN `con` as t4 on t4.id=t1.cond ORDER BY id DESC";
mysql_select_db($database_DBConn, $DBConn);
$result = mysql_query($sql) or die("Query failed : " . mysql_error());

while ($line = mysql_fetch_assoc($result))
{
$value[] = $line;
}

$pagerOptions = array('mode' => 'Sliding', 'delta' => 3, 
'perPage' => 10, 'itemData' => $value,
'prevImg'  => '<img src="../images/previous_page.png" border="0"/>',
'nextImg'  => '<img src="../images/next_page.png" border="0" />',
'urlVar' => 'pageNum');
$pager =& Pager::factory($pagerOptions);
$data = $pager->getPageData();
if (!is_array($data)) {
    $data = array();
}

$smarty = new Smarty;
$smarty->assign('cards', $data);
$smarty->assign('pager_links', $pager->links);
$smarty->assign('page_numbers', array('current' => $pager->getCurrentPageID(), 'total' => $pager->numPages()));
$smarty->assign('sname', $title);

$smarty->display('../../templates/listcards.dwt');
?>

 

If you need to see the template let me know and I will post it as well.

 

Thanks,

 

whit3fir3

I have been playing around with this some this evening and I have discovered that the problem is localize to Smarty.  I rolled my version of Smarty back to 2.6.26 thinking that the problem I was having might of had something to do with using a BETA version. This did not fix the problem.  While playing around with the latest stable release of Smarty I brilliant idea to turn debugging output on for SMARTY.  I turned it on and loaded up the page in question and the first page of results are displayed error free.  I click the NEXT PAGE link at the bottom and Smarty basically threw up in my browser.  All of the errors were "Undefined offset" errors which after some research appears to be a common problem with PHP.  My question now, if someone can help me out, is why does the first page of results load successfully and every page after that fail and is there anything that can be done to fix this?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.