Solved

PHP : how to assign variable from mysql to smarty

Posted on 2008-10-24
1
498 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

772 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

9 Experts available now in Live!

Get 1:1 Help Now