Results per page problem with smarty - urgent please help
Posted: Tue May 25, 2004 5:50 am
hi everyone,
i am stuck in a very difficult situation. i am making a site in php, mysql using smarty.
now i am not able to implement results per page (showing results per page say 10 on one page and then 10 on others and so on....).
i have a page show_cards.php which contains the code which retrieves books from the database.
$cards = array();
$cards = get_cards(); // thru function call----->select * from cards
Now the cards returns an associative array, which i am am able to fetch and store in another array variable to show in the template file:
foreach($cards as $card)
{
$card_id = $card['card_id'];
$card_title = $card['card_title'];
$cards_array[$card_id] = $card_title;
}
//assign card_array to a variable to use in template
$smarty->assign("cards_array",$cards_array);
$smarty->display("show_cards.tpl");
Now in the template file (show_cards.tpl), i have written following code:
{foreach key=key item=item from=$cards_array}
<tr>
<td>{$key}</td><td>{$item}</td>
</tr>
{/foreach}
Here $key is the card_id and item is card_title.
Now using this code, i am getting all the cards on the same page, i am not able to figure out how to get limited number of cards on one page and rest on other (results per page), so that the user can click next or back to browse other cards.
Plz help.
Thanx.
Gaurav
i am stuck in a very difficult situation. i am making a site in php, mysql using smarty.
now i am not able to implement results per page (showing results per page say 10 on one page and then 10 on others and so on....).
i have a page show_cards.php which contains the code which retrieves books from the database.
$cards = array();
$cards = get_cards(); // thru function call----->select * from cards
Now the cards returns an associative array, which i am am able to fetch and store in another array variable to show in the template file:
foreach($cards as $card)
{
$card_id = $card['card_id'];
$card_title = $card['card_title'];
$cards_array[$card_id] = $card_title;
}
//assign card_array to a variable to use in template
$smarty->assign("cards_array",$cards_array);
$smarty->display("show_cards.tpl");
Now in the template file (show_cards.tpl), i have written following code:
{foreach key=key item=item from=$cards_array}
<tr>
<td>{$key}</td><td>{$item}</td>
</tr>
{/foreach}
Here $key is the card_id and item is card_title.
Now using this code, i am getting all the cards on the same page, i am not able to figure out how to get limited number of cards on one page and rest on other (results per page), so that the user can click next or back to browse other cards.
Plz help.
Thanx.
Gaurav