|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
zukowskp Smarty n00b
Joined: 15 Jul 2008 Posts: 1
|
Posted: Tue Jul 15, 2008 7:20 am Post subject: Smarty - Pagination What's wrong? |
|
|
Hello,
I try to create some smarty page and I have problem with pagination :S
.html
Code: | {include file="naglowek.html"}
<table>
<tr>
<td><b>Name:</b></td>
<td><b>Category:</b></td>
<td><b>Details:</b></td>
</tr>
<tr></tr>
Items {$paginate.first}-{$paginate.last} out of {$paginate.total} displayed. <br />
{section name=res loop=$results}
<tr>
<td>{$results[$_data]}</td>
</tr>
{/section}
{* display pagination info *}
{paginate_prev} {paginate_middle} {paginate_next}
</table>
{include file="stopka.html"} |
.php
Code: | <?
session_start();
require('lib/SmartyPaginate.class.php');
$smarty =& new Smarty;
// required connect
SmartyPaginate::connect();
// set items per page
SmartyPaginate::setLimit(100);
// assign your db results to the template
$smarty->assign('results', get_db_results());
// assign {$paginate} var
SmartyPaginate::assign($smarty);
// display results
function get_db_results() {
$link = mysql_connect('', '', '');
mysql_select_db('');
$query = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM drinks LIMIT %d,%d",
SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit());
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
// collect each record into $_data
$data[] = $row;
}
// now we get the total number of records from the table
$query = "SELECT FOUND_ROWS() as total";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
SmartyPaginate::setTotal($row['total']);
mysql_free_result($result);
mysql_close($link);
return $data;
}
$smarty->display('drink.html');
//print_r($row);
?> |
Could you tell me what's wrong and help me correct my code?
Thank you. |
|
Back to top |
|
jareeq Smarty n00b
Joined: 21 Jul 2008 Posts: 1
|
Posted: Mon Jul 21, 2008 4:20 pm Post subject: |
|
|
@zukowskp,
read variable in template as:
Code: | {section name=res loop=$results}
<tr>
<td>{$results[res].column_name_in_sql_table}</td>
</tr>
{/section} |
smarty in your script dont know what $_data is,
helpfully - you can use :
Code: | $smarty->debug_tpl = 'path_to_file where_smarty_debug.tpl_is';
$smarty->debugging = true; |
after smarty object call - with debug enabled you can find info about smarty variables.
of course there are more options available - check crash couse and well done sample app on smarty page (guestbook)
pzdr/cheers |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|