FastTemplates and MySQL data?

From: Date: Thu, 28 Dec 2000 17:04:47 +0000
Subject: FastTemplates and MySQL data?
References: 1  Groups: php.db php.general 
Request: Send a blank email to php-general+get-32092@lists.php.net to get a copy of this message
This is a second post, since no one responded the first time... :) Can I somehow pass FastTemplates a MySQL result array, and also pass it a template pointer, and get a resultant page? I really just want to set up a script where a Select parameter is passed in, a result set array is generated, and the array is evaluated against an array of template {} variables. This way I can call pages with essentially one variable. Any ideas? The original post is below. TIA! andrew > 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... > >

« previous php.general (#32092) next »