Support Forums

how to display var array in smary template

This is a discussion on how to display var array in smary template within the Templates, HTML, CSS, and Design Help forums, part of the General category; hello i stored array in var then i want to display this array in the smarty the field in database ...


Go Back   68 Classifieds Forums > General > Templates, HTML, CSS, and Design Help

Reply
 
Thread Tools Display Modes
Old 05-19-2009, 01:32 PM   #1
Customer
 
Abdulaziz's Avatar
 
Join Date: Sep 2008
Location: Kuwait
Posts: 51
Rep Power: 11
Abdulaziz is on a distinguished road
Default how to display var array in smary template

hello

i stored array in var then i want to display this array in the smarty the field in database where they stored in the var are name, email, comment ??? how can i do it

look at what i did
PHP Code:
{foreach from=$rs item="entry"}
        {
$smarty.const.LANG_NAMEE}  :{$entry.name}
        {
$smarty.const.LANG_EMAIL}  :{$entry.email}
        {
$smarty.const.LANG_COMMENT}:{$entry.comment}
        {/foreach} 
but it didn't work with me

so any idea for this ?

Last edited by Abdulaziz; 05-19-2009 at 01:35 PM.
Abdulaziz is offline   Reply With Quote
Old 05-19-2009, 01:39 PM   #2
curmudgeon
 
Join Date: Mar 2006
Posts: 5,342
Rep Power: 132
Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light
Default

Quote:
Originally Posted by Abdulaziz
hello

i stored array in var then i want to display this array in the smarty the field in database where they stored in the var are name, email, comment ??? how can i do it

look at what i did
PHP Code:
{foreach from=$rs item="entry"}
        {
$smarty.const.LANG_NAMEE}  :{$entry.name}
        {
$smarty.const.LANG_EMAIL}  :{$entry.email}
        {
$smarty.const.LANG_COMMENT}:{$entry.comment}
        {/foreach} 
but it didn't work with me

so any idea for this ?
This isnt really enough detail to go on.

Is your arfray multi-dimensionl?

Have you assigned the value of $rs to the template?

Try putting this in your template for testing purposes......

{php}print_r($rs){/php}


This should print out the array in the template, probably at the top of the page, post what it prints out here.
__________________
Larry

Knowledge learned is more valuable than knowledge given.
Lhotch is offline   Reply With Quote
Old 05-19-2009, 02:00 PM   #3
Customer
 
Abdulaziz's Avatar
 
Join Date: Sep 2008
Location: Kuwait
Posts: 51
Rep Power: 11
Abdulaziz is on a distinguished road
Default

i will explain

i created class guestbook which have this method
PHP Code:
function GetRecord()
   {
        global 
$db,$class_tpl;
        
$sSQL="SELECT * FROM ".PREFIX."gustbook";
        
$result=$db->query($sSQL);
        
$rs=$result->fetch();
                  
$class_tpl->assign('rss'$rs);
                RETURN;
   } 
and in the index.php
PHP Code:
require_once('modules/gustbook/includes/class.php');        
$gustbook = new Guestbook();
$gustbook->GetRecord();
$class_tpl->assign('body','gustbook.tpl.php'); 
and then i made gustbook.tpl
PHP Code:
{foreach from=$rs item="entry"}
        {
$smarty.const.LANG_NAMEE}  :{$entry.name}
        {
$smarty.const.LANG_EMAIL}  :{$entry.email}
        {
$smarty.const.LANG_COMMENT}:{$entry.comment}
        {/foreach} 
these are the detail and the problem is in the last step i can't display the array which it stored in $rss


this is my first module and i would like to be in the right way so any idea please
Abdulaziz is offline   Reply With Quote
Old 05-19-2009, 02:06 PM   #4
curmudgeon
 
Join Date: Mar 2006
Posts: 5,342
Rep Power: 132
Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light
Default

Assuming your the query to the database is working and collecting data the obvious problem I see is that you are assigning the php variable $rs to the template variable rss with this line...

$class_tpl->assign('rss', $rs);

Then in the tamplate you are trying to get data from the smarty variable $rs with the following line

{foreach from=$rs item="entry"}


there is no smarty variable $rs, its rss as it appears in the template asignment.
__________________
Larry

Knowledge learned is more valuable than knowledge given.
Lhotch is offline   Reply With Quote
Old 05-19-2009, 02:40 PM   #5
Customer
 
Abdulaziz's Avatar
 
Join Date: Sep 2008
Location: Kuwait
Posts: 51
Rep Power: 11
Abdulaziz is on a distinguished road
Default

thanks for your fast replay

i corrected the var $rss and when i test it i get only the first string from each field then i tried this code
PHP Code:
{foreach from=$rss item="entry"}
        {
$smarty.const.LANG_NAMEE}  :{$entry}
        {/foreach} 
it's work but it display only one row.

what i want is to split the array and display it in template
thanks in advance
Abdulaziz is offline   Reply With Quote
Old 05-19-2009, 02:58 PM   #6
68 Classifieds Staff
 
Eric Barnes's Avatar
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 5,493
Rep Power: 132
Eric Barnes is just really nice Eric Barnes is just really nice
Default

Try this:
PHP Code:
function GetRecord()
{
    global 
$db;
    
$sSQL="SELECT * FROM ".PREFIX."gustbook";
    
$result=$db->query($sSQL);
    
$data=$result->fetch();
    return 
$data;
}

// This is your normal file
require_once('modules/gustbook/includes/class.php');        
$gustbook = new Guestbook();
$data $gustbook->GetRecord();
$class_tpl->assign('rss'$data);
$class_tpl->assign('body','gustbook.tpl.php'); 
__________________
Eric Barnes
68 Classifieds Developer
Customer Area | Issue Tracker | Documentation | 68C Mods | 68 @ Twitter | My Modules
Eric Barnes is offline   Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hook for template display()? cheesegrits Technical Support 4 01-14-2008 12:59 PM


All times are GMT -4. The time now is 07:02 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0