Solved

PHP : how to assign variable from mysql to smarty

Posted on 2008-10-24
1
502 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now