Re: pulling in template file in var and populating vars?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



blackwater dev wrote:
I have a chunk of html data that I want to output for each iteration through
a db result

while($result){

   $list.=file_get_contents("my_template_file.php");

}
return $list;

The template file looks like this:

<table>
    <tr>
         <td><?php echo $result["name"];?></td>
    </tr>
</table>

I basically want a good way to keep the template file out of the class so I
don't have to code:
 $list.="<table><tr>...etc

The problem is with the method I have, it doesn't translate the
vars...what's the best way to do this?

Thanks!


I wouldn't use a class/function to output anything. Why not just return the data, and loop thru that?

function myFunction() {
/* ----- Code ----- */
while ( $data = mysql_fetch_array ( $result, MYSQL_ASSOC ) ) {
	$return_data[] = $data;
}
}
return $return_data;



$myData = myFunction();
foreach ( $myData as $data ) {
	echo <<<END
<table>
	<tr>
		<td>$data["name"]</td>
	</tr>
</table>
END;
}

--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
jnichel@xxxxxxxxxxxxxxxxxxxxxxxxxxx

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux