Please: XTemplate help?
| From: | Jaxon | Date: | Sat, 20 Jan 2001 17:04:09 +0000 |
| Subject: | Please: XTemplate help? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-35810@lists.php.net to get a copy of this message | ||
Hi Debreceni,
I need to use a template parser, and XTemplate looks like it will do what I
need, but I'm not sure how. I can use mysql_fetch_array to produce an array
of field_name:value. If I use {field} names in the html template, can I use
XTemplate to take the array and parse?
This is what I have so far - please look at the ASSIGN step
<?
$id=1; //parameter for sql select, determines which row is selected
$user="user";
$pass="pass";
$database="database";
$sql="select * from table where id = $id"; //returns ONE row (id is a PK)
$link_id = mysql_connect($database); //identify connection handle
if (!$link_id) { die(sql_error()); } //test for connection handle
else { mysql_select_db($database, $link_id) } //select database
$result = mysql_query($sql, $user, $pass); //return row to php
$page_array = mysql_fetch_array($result);
//this creates array of field name:data,
//eg $page_array[firstfield] has value of 'firstfield' for $id
require "xtpl.p"; //include XTemplate engine
require "html.xtpl"; //html layout file with field names e.g. {firstfield}
$xtpl->assign($page_array); //HELP! How is this step done?
//I already have an array that assigns field
//names to data elements, how can I skip this?
//I don't want to assign each element since then
//I would need one .p page for each .xtpl page
$xtpl->parse("main");//replace {field} with matching result row element
$xtpl->out("main");` //send final html page to browser
?>
Does this make sense?
Thanks in advance for any help!
Regards,
Jaxon