Re: Database results example
| From: | Monte Ohrt | Date: | Mon, 29 Jan 2001 16:29:21 +0000 |
| Subject: | Re: Database results example | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-22@lists.php.net to get a copy of this message | ||
An added note, you can assign data either value by value, or you can
pass an array structure to assign()
$smarty->assign("var","value");
$data = array(
"var1" => "val1",
"var2" => "val2",
"var3" => "val3"
);
$smarty->assign($data);
Joris Trooster / Interstroom wrote:
>
> Hi,
>
> This is not a question you should ask here, but below a basic example for
> php/mysql:
>
> In your php page:
>
> // Include Smarty class
> require("Smarty.class.php");
> // Open database connections
> mysql_connect("localhost","user","password")
> or die("Unable to connect to SQL server");
> mysql_select_db("database")
> or die("Unable to select database");
> // Use Smart template
> $template = new Smarty;
> $value_array = array();
> // Database query
> $query = mysql_query("select * from table");
> // Loop through values
> while($row=mysql_fetch_row($query)) {
> array_push($value_array,$row[0]);
> }
> // Assign the array with the values from the
> // database to the template
> $template->assign("value_array", $value_array);
> // Print template
> $template->display("path/to/template.tpl");
>
> And a very basic template.tpl:
>
> {section name=example loop=$value_array}
> {$example/value_array}<BR>
> {/section}
>
> Good Luck,
> Joris Trooster
> Interstroom
> NL
>
> ---
> You are currently subscribed to smarty as: monte@ispi.net
> To unsubscribe send a blank email to $subst('Email.Unsub')
--
Monte Ohrt <monte@ispi.net>
http://www.ispi.net/