while ( $rowData = mysql_fetch_array($result))
{
    list($fieldName,  $fieldValue) = each($rowData);
    $template->assign("$fieldName", $fieldValue);
}


----- Original Message -----
From: "Jaxon" <[EMAIL PROTECTED]>
To: "Kristi Russell" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Saturday, January 20, 2001 2:03 PM
Subject: Re: [PHP] Please: XTemplate help?


> Kristi,
>
> That makes more sense, thanks, but one problem - I don't want to have to
do:
>
> $template->assign("FIELD2", $row[fieldname2]);
>
> If I've already called mysql_fetch_array, then I have an array like this:
>
> field1:field1_data
> field2:field2_data
> field3:field3 data
>
> Is there any way to use the array itself as the assignment, or tell
> XTemplate to do so?  That way I can use one file to generate pages from
> different templates.
>
> Regards,
> Jaxon
>
>
> On 1/20/01 12:26 PM, "Kristi Russell" <[EMAIL PROTECTED]> wrote:
>
> > require "xtpl.p"; //include XTemplate engine
> >
> > //don't need this - wrong.
> >> require "html.xtpl"; //html layout file with field names e.g.
{firstfield}
> >
> > You need to create a new instance of the Xtemplate class so:
> > //assign the new instance to a variable name you'll use - I called it
> > $template
> > //and I specified which "html layout file" to use.
> >
> > $template = new Xtemplate("html.tpl"); // I name them tpl not xtpl
*shrug*
> >
> > while($row = mysql_fetch_array($result))
> > {
> >   $template->assign("FIELD1", $row[fieldname]);
> >   //FIELD1 being the name you're going to use in the layout file by
> > {FIELD1}
> >   //$row being the name of the array you fetched, field name being the
> > fieldname in the database
> >
> >   $template->assign("FIELD2", $row[fieldname2]);
> >
> >   $template->parse("main");//replace {field} with matching result row
> > element
> >   $template->out("main");` //send final html page to browser
> > }
> >
> >
> >
> > Kristi
> >
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to