Re: Please: XTemplate help?

From: Date: Sat, 20 Jan 2001 23:47:26 +0000
Subject: Re: Please: XTemplate help?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-35856@lists.php.net to get a copy of this message
Cool, so just iterate through the array and sort it into the template assignment - quite nice! Thanks for the pointers Kristi! Regards, Jaxon On 1/20/01 3:37 PM, "Kristi Russell" <darkfires@darkfires.com> wrote: > while ( $rowData = mysql_fetch_array($result)) > { > list($fieldName, $fieldValue) = each($rowData); > $template->assign("$fieldName", $fieldValue); > } > > > ----- Original Message ----- > From: "Jaxon" <jaxon@salamander.net> > To: "Kristi Russell" <darkfires@darkfires.com> > Cc: <php-general@lists.php.net> > 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" <darkfires@darkfires.com> 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: php-general-unsubscribe@lists.php.net >> For additional commands, e-mail: php-general-help@lists.php.net >> To contact the list administrators, e-mail: php-list-admin@lists.php.net >> >

« previous php.general (#35856) next »