Support Forums


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

 
LinkBack Thread Tools Display Modes
Old 05-19-2009, 12:32 PM   #1
Junior Member
 
Abdulaziz's Avatar
 
Join Date: Sep 2008
Location: Kuwait
Posts: 19
Rep Power: 3
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 12:35 PM.
Abdulaziz is offline   Reply With Quote
Old 05-19-2009, 12:39 PM   #2
Moderator
 
 
Join Date: Mar 2006
Posts: 4,218
Rep Power: 103
Lhotch is just really niceLhotch is just really nice
Default

Quote:
Originally Posted by Abdulaziz View Post
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.
(Please note: I am not a 68C employee. I am a customer and volunteer who helps with questions where I can and the forums spam free)

Set your site apart from the competition with one of my modules......
Google Map Module | You Tube Module | Google Calendar Module | Event Calendar Module

68 Classifieds Important Links
Customer Area | Issue Tracker | Knowledge Base | User Manuals
Lhotch is offline   Reply With Quote
Old 05-19-2009, 01:00 PM   #3
Junior Member
 
Abdulaziz's Avatar
 
Join Date: Sep 2008
Location: Kuwait
Posts: 19
Rep Power: 3
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, 01:06 PM   #4
Moderator
 
 
Join Date: Mar 2006
Posts: 4,218
Rep Power: 103
Lhotch is just really niceLhotch is just really nice
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.
(Please note: I am not a 68C employee. I am a customer and volunteer who helps with questions where I can and the forums spam free)

Set your site apart from the competition with one of my modules......
Google Map Module | You Tube Module | Google Calendar Module | Event Calendar Module

68 Classifieds Important Links
Customer Area | Issue Tracker | Knowledge Base | User Manuals
Lhotch is offline   Reply With Quote
Old 05-19-2009, 01:40 PM   #5
Junior Member
 
Abdulaziz's Avatar
 
Join Date: Sep 2008
Location: Kuwait
Posts: 19
Rep Power: 3
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, 01:58 PM   #6
68 Classifieds Staff
 
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 4,842
Rep Power: 111
Eric Barnes is a jewel in the rough
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
Please do not send me a private message asking for support. Instead use these open forums or our ticket system.

Customer Area | Issue Tracker | Documentation | 68C Mods | Submit a Ticket | 68 @ Twitter | My Modules
Eric Barnes is offline   Reply With Quote
Old 05-19-2009, 02:08 PM   #7
Moderator
 
 
Join Date: Mar 2006
Posts: 4,218
Rep Power: 103
Lhotch is just really niceLhotch is just really nice
Default

Quote:
Originally Posted by Eric Barnes View Post
Try this:
The problem here as I see it is he is only pulling 1 record from the database and doesnt seem to be stating which record he is pulling.

He is using....

$data=$result->fetch();

which uses mysql_fetch_array to load the returned array into $data thereby making it a multidimensional array.

then at the template level looping over the $data array(which there is nothing to loop over because there was only 1 record pulled from DB) and trying to display the contents as a regular variable when in essence its another array.
__________________
Larry.
(Please note: I am not a 68C employee. I am a customer and volunteer who helps with questions where I can and the forums spam free)

Set your site apart from the competition with one of my modules......
Google Map Module | You Tube Module | Google Calendar Module | Event Calendar Module

68 Classifieds Important Links
Customer Area | Issue Tracker | Knowledge Base | User Manuals
Lhotch is offline   Reply With Quote
Old 05-19-2009, 03:10 PM   #8
Junior Member
 
Abdulaziz's Avatar
 
Join Date: Sep 2008
Location: Kuwait
Posts: 19
Rep Power: 3
Abdulaziz is on a distinguished road
Default

hello Eric

i did what did you write and nothing happen

look at what has appeared
5
a
g

"5 is the id , a is the first of abdulaziz, g is the first of good"
that what are appear
the record in the database as picture in attachment
also u can visit the url to see that ??????? ?????? ? ????? ??????? ??????? ?????? ?????? ?????? ?????????
and one more thing if it possible to setup 68classified in the localhost?
Attached Images
File Type: jpg db.jpg (12.1 KB, 2 views)
Abdulaziz is offline   Reply With Quote
Old 05-19-2009, 04:30 PM   #9
68 Classifieds Staff
 
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 4,842
Rep Power: 111
Eric Barnes is a jewel in the rough
Default

Yes I think Larry was on to something. See if this works:
PHP Code:
function GetRecord()
{
    global 
$db;
    
$sSQL="SELECT * FROM ".PREFIX."gustbook";
    
$result=$db->query($sSQL);
    
$data=array();
    while(
$rs=$result->fetch())
    {
        
$data[]=$rs;
    }
    
$result->freeResult();
    return 
$data;

__________________
Eric Barnes
68 Classifieds Developer
Please do not send me a private message asking for support. Instead use these open forums or our ticket system.

Customer Area | Issue Tracker | Documentation | 68C Mods | Submit a Ticket | 68 @ Twitter | My Modules
Eric Barnes is offline   Reply With Quote
Old 05-20-2009, 08:23 AM   #10
Junior Member
 
Abdulaziz's Avatar
 
Join Date: Sep 2008
Location: Kuwait
Posts: 19
Rep Power: 3
Abdulaziz is on a distinguished road
Default

I am greatful that you solved my problem it's working very well now
sending you my best regards
Abdulaziz is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hook for template display()? cheesegrits v4 Questions & Support 4 01-14-2008 11:59 AM
Array Jessej v3.1 Questions & Support 18 11-29-2007 09:04 AM
extra field check boxes output "array" markyy v3.1 Questions & Support 0 11-16-2007 12:22 AM
listing extra field value when it is an array? Mike-N-Tosh v3.1 Modules & Modifications 13 04-21-2007 09:31 AM
Displaying a Multidimensional Array Results in Smarty Maffo v3.1 Questions & Support 7 12-20-2006 08:41 AM


All times are GMT -4. The time now is 05:43 AM.


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