Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Is there something to get total records of mysql query?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
lastexile
Smarty Rookie


Joined: 03 Jan 2008
Posts: 15

PostPosted: Thu Jan 03, 2008 6:01 pm    Post subject: Is there something to get total records of mysql query? Reply with quote

I was wondering if SMARTY provides something for a total record count of a mysql query.

My query in the PHP is

$sql = "SELECT * FROM user_rating WHERE item_id = '".$_GET['item_id']."'";
$handle = $db->sql_query($sql);
$rating_info = $db->sql_fetchrowset($handle);
$smarty->assign('rating_info', $rating_info);

In the HTML template, is there something I can use to get the total records?

thanks1
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Jan 03, 2008 6:06 pm    Post subject: Reply with quote

You can assign the record count from MYSQL, or count the array items in the template.
Back to top
View user's profile Send private message Visit poster's website
lastexile
Smarty Rookie


Joined: 03 Jan 2008
Posts: 15

PostPosted: Thu Jan 03, 2008 6:16 pm    Post subject: Reply with quote

mohrt wrote:
You can assign the record count from MYSQL, or count the array items in the template.


Hi, could you provide examples of both?

Thanks!
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Jan 03, 2008 6:32 pm    Post subject: Reply with quote

http://www.devscripts.net/smarty/

http://www.smarty.net/manual/en/language.modifiers.php (shows how to count array elements)
Back to top
View user's profile Send private message Visit poster's website
lastexile
Smarty Rookie


Joined: 03 Jan 2008
Posts: 15

PostPosted: Thu Jan 03, 2008 7:02 pm    Post subject: Reply with quote

mohrt wrote:
http://www.devscripts.net/smarty/

http://www.smarty.net/manual/en/language.modifiers.php (shows how to count array elements)


Okay, I'll go and check it out. Thanks..

it's too bad smarty doesnt have a simple tag to get total mysql query like coldfusion. With coldfusion, it's just #queryname.recordcount# and it's so simple.

Thanks!
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Jan 03, 2008 7:46 pm    Post subject: Reply with quote

Smarty is only a template language. Cold fusion is a programming language, such as PHP itself. In PHP, there are "simple" ways to get your record count, it is up to you to assign that to Smarty.
Back to top
View user's profile Send private message Visit poster's website
lastexile
Smarty Rookie


Joined: 03 Jan 2008
Posts: 15

PostPosted: Thu Jan 03, 2008 11:50 pm    Post subject: Reply with quote

mohrt wrote:
Smarty is only a template language. Cold fusion is a programming language, such as PHP itself. In PHP, there are "simple" ways to get your record count, it is up to you to assign that to Smarty.


Quite true.. thanks for clarifying.

I decided to do the following and hopefully it'll work.

$rating_info_total = mysql_num_rows($handle);
$smarty->assign('rating_info_total', $rating_info_total);
Back to top
View user's profile Send private message
master_kaos
Smarty Regular


Joined: 02 Aug 2007
Posts: 54

PostPosted: Mon Jan 07, 2008 3:40 pm    Post subject: Reply with quote

you could cut it down to one line by
$smarty->assign('rating_info_total', mysql_num_rows($handle));
Unless of course you need the variable in your PHP code
Back to top
View user's profile Send private message
lastexile
Smarty Rookie


Joined: 03 Jan 2008
Posts: 15

PostPosted: Fri Oct 10, 2008 4:47 am    Post subject: Reply with quote

Awesome!

thanks!

master_kaos wrote:
you could cut it down to one line by
$smarty->assign('rating_info_total', mysql_num_rows($handle));
Unless of course you need the variable in your PHP code
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP