FastTemplates and MySQL data?
| From: | andrew | Date: | Fri, 22 Dec 2000 03:07:28 +0000 |
| Subject: | FastTemplates and MySQL data? | ||
| References: | 1 | Groups: | php.db php.general |
| Request: | Send a blank email to php-general+get-31520@lists.php.net to get a copy of this message | ||
Hi,
<NEWBIE ALERT>
Can anyone show me an example (or better, point me to some code)
where the FastTemplate class pulls info from MySQL?
e.g. something like this maybe?:
<?
$sql = "select * from database where id = id"; //to get one row
$location = "path/to/template/directory"; //one per template set
mysql_connect($hostname, $user, $password);
$result = mysql_db_query ("database", $sql);
while ($row = mysql_fetch_assoc ($result))
{
echo $row["field1"]; //maybe build dynamically with a for loop?
echo $row["field2"];
}
mysql_free_result ($result);
$tpl = new FastTemplate($location);
$tpl->define(array ($result, main => main.tpl)); // help!
?>
So basically every page (or page section) can be stored as one row in a
database and to get your script to generate a different page you just have
to pass $sql and $location, since $location defines a set of templates that
work together to define your page and $sql defines which result set will get
parsed against the *.tpl in $location
I can't believe that this hasn't been done before, but I'm too green to know
exactly what to do here...
thanks in advance for any advice!
regards,
andrew