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

{html_options} functions along with array passed from DB

 
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
jaxyeh
Smarty Rookie


Joined: 07 Aug 2003
Posts: 6

PostPosted: Thu Aug 07, 2003 3:34 pm    Post subject: {html_options} functions along with array passed from DB Reply with quote

Hello Guys,

I am starting to develop some huge php project along with smarty templates... However, I came up with one problem using {html_options} along with array that depends on DATABASE... Which means, array are not defined through by regular assigned method, but array retrieved through DATABASE. so I use SECTION LOOP to define array variables, but how can I define them without loop or using {html_options}??

I decided to do those follow method, using {section loop} above the {html_options}. It works fine. But I wasn't sure if its logical correction, so I am asking you guys who're expert with Smarty templates to observe and give me feedback on this method...

here 's PHP code:
[php:1:01a2a09dbf]
$query = "SELECT * FROM groups ORDER BY groupid ASC";
if ($groups = $db->array_query($query)) {
$smarty->assign('groups', $groups);
$smarty->assign('group_id', '2');
}
[/php:1:01a2a09dbf]

here's TPL code using {section}:
Code:

{section name=i loop=$groups}
{html_options values=$groups[i].groupid selected=$group_id output=$groups[i].name}
{/section}


thanks!!

-Jax
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Aug 07, 2003 3:43 pm    Post subject: Reply with quote

hmm, htmloptions already takes *arrays* as parameters for values and output. i would suggest tweaking your db-result, so that smarty can handle them easily:

[php:1:6b2e921f4f]
if ($groups = $db->array_query($query)) {
$groups_opts = array();
foreach ($groups as $group) {
$groups_opts[$group['groupid']]=$group['name'];
}
$smarty->assign('groups_opts', $groups_opts);
$smarty->assign('group_id', '2');
}
[/php:1:6b2e921f4f]

after that you have a hash-array in your template mapping id->name.
that fits perfectly for {html_options}'s options-attribute:

Code:

{html_options options=$groups_opts selected=$group_id}


no need for growing your own loops here Smile


Last edited by messju on Thu Aug 07, 2003 3:59 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jaxyeh
Smarty Rookie


Joined: 07 Aug 2003
Posts: 6

PostPosted: Thu Aug 07, 2003 3:55 pm    Post subject: wow! Reply with quote

That's the perfect answer I am looking for!!! THANKS!!

your an angel! Smile

-jax
Back to top
View user's profile Send private message Visit poster's website
mikeken
Smarty Regular


Joined: 13 Aug 2003
Posts: 57
Location: MN

PostPosted: Wed Aug 20, 2003 3:02 am    Post subject: Reply with quote

are you guys using ezsql or whatever its called?
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
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