Solved

PHP : how to assign variable from mysql to smarty

Posted on 2008-10-24
1
504 Views
Last Modified: 2013-12-13
hi, i want to pull 1 column of data from mysql and put it into
smarty template that use

listmenu or html_option

 i have something like this

====================================================================================
$query = "SELECT * FROM package";
$query_result = @mysql_query ($query) OR error(mysql_error());
while ($info = @mysql_fetch_array($query_result))
{
      $types_temp = array();
      
      $types_temp = $info['pack_name'];

}

STemplate::assign('types_temp', $types_temp);
=================================================================================

TPL:
            <select name="package">
             <option value='null'>-- none --</option>
            {html_options options=$packnamez.sohai }
           </select>


does my TPL correct? i cant figure it work :(
some 1 please help
0
Comment
Question by:alicca
1 Comment
 
LVL 6

Accepted Solution

by:
hampus_b earned 500 total points
ID: 22802787
see below. First, you have to add every row to array by assinging to $types_temp[] (note the []).
Then assign that variable and finally use it in smarty.
$query = "SELECT * FROM package";
$query_result = @mysql_query ($query) OR error(mysql_error());
while ($info = @mysql_fetch_array($query_result))
{
      $types_temp = array();
      
      $types_temp[] = $info['pack_name'];
 
}
 
STemplate::assign('types_temp', $types_temp);
=================================================================================
 
TPL:
            <select name="package">
             <option value='null'>-- none --</option>
            {html_options options=$types_temp }
           </select>

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question