View previous topic :: View next topic |
Author |
Message |
lastexile Smarty Rookie
Joined: 03 Jan 2008 Posts: 15
|
Posted: Thu Jan 03, 2008 6:01 pm Post subject: Is there something to get total records of mysql query? |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jan 03, 2008 6:06 pm Post subject: |
|
|
You can assign the record count from MYSQL, or count the array items in the template. |
|
Back to top |
|
lastexile Smarty Rookie
Joined: 03 Jan 2008 Posts: 15
|
Posted: Thu Jan 03, 2008 6:16 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
|
Back to top |
|
lastexile Smarty Rookie
Joined: 03 Jan 2008 Posts: 15
|
Posted: Thu Jan 03, 2008 7:02 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jan 03, 2008 7:46 pm Post subject: |
|
|
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 |
|
lastexile Smarty Rookie
Joined: 03 Jan 2008 Posts: 15
|
Posted: Thu Jan 03, 2008 11:50 pm Post subject: |
|
|
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 |
|
master_kaos Smarty Regular
Joined: 02 Aug 2007 Posts: 54
|
Posted: Mon Jan 07, 2008 3:40 pm Post subject: |
|
|
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 |
|
lastexile Smarty Rookie
Joined: 03 Jan 2008 Posts: 15
|
Posted: Fri Oct 10, 2008 4:47 am Post subject: |
|
|
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 |
|
|