Re: Database results example
| From: | Joris Trooster / Interstroom | Date: | Mon, 29 Jan 2001 15:45:28 +0000 |
| Subject: | Re: Database results example | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-21@lists.php.net to get a copy of this message | ||
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