I'm trying to make a simple template system because I don't want to use Smarty or anything like that.
My current problem is that I can't make 1 tag print every result from a while loop. It only prints the first result.
public $TplKey = array();
public function GetContent($file, $data) {
$template = file_get_contents($file);
foreach($data as $key => $value) {
$template = str_replace('{'.$key.'}', $value, $template);
}
return $template;
}
public function View($file) {
return $this->GetContent($file, $this->TplKey);
}
public function TplKeyAdd($key, $value) {
return $this->TplKey += array($key => $value);
}
public function testing() {
global $DBHandle;
$q = $DBHandle->mysqli->query("SELECT * FROM site_users");
while($qf = $q->fetch_array()) {
$r = $this->TplKeyAdd("var", $qf["user_name"]);
}
return $r;
}
Then, later on in my .TPL file I call {var}. But it only shows the first database row (as stated). I want it to show every row it can find. How can I solve this?
returnin a while loop, you'll only ever get one iteration of it