Hi,
In my script I use some include files with class definitions (class for db connection, auth class, session class and so on...). The code looks something like this:
<?
$post_tpl = new template();
$post_tpl -> load('sometemplate'); //loadis a template
$db -> query("SELECT * FROM `table`"); //this query gives e.g. 100 results
$userdata = new user; //creating a user object
while ($post = $db -> fetch_row()) {
$userdata -> setData($post['author']); //setting the user fields with proper values
$post_tpl -> blocks = array (
"someblock1" => $var1,
"someblock2" => $var2,
...
);
$post_tpl -> parse(); //parsing the template
echo $post_tpl -> parsed; //outputting
}
?>
The problem is that when I use the setData method it uses some database queries which unfortunately affect the query in while loop 😐 One solution could be to create a new connection in setData function but doing it every time would be inefficient. Is there other way to do this? Also, some crits on the code would be helpful as my OOP in PHP started few days ago 🙂
Regards,
msq