soo I am trying to create a navigation bar to my website.
I am using a small template engine I have build(with preg replace functions) but i have this problem.
I am trying to output a number of mysql rows from a return function inside an template assign class but the thing is I am getting only the first row outputed when I use return. meanwhile if I echo the rows from the function I get all the rows but I don't get them inside the template but I get them at the top of the Html file above everything.
here is the function with her assignment into template file:
function navigation(){
global $result, $db;
$page_query = $db->query("SELECT * FROM `pages` ");
if ($db->num_rows($page_query) > 0) {
while($result = $db->fetch_array($page_query)){
return '<li>
<a href="index.php?page='. $result['id'] .'">'.$result['name'].'</a>
</li>';
}
}
}
$tp->assign('NAV_BAR', navigation());
and here is the template displaying and assignment class:
public $filename;
public $assigned_vars = array();
public $value = array();
public function assign($key, $value)
{
$this->assigned_vars[$key] = $value;
}
public function display($filename)
{
if(file_exists($filename))
{
$output = file_get_contents($filename);
foreach($this->assigned_vars as $key => $value)
{
$output = preg_replace('/{%'.$key.'%}/', $value, $output);
$output = str_replace('{%' . $key . '%}', $value, $output);
}
echo $output;
}
else{
echo "Missing template error";
}
}
any ideas what to do???