Jump to content

tsz

New Members
  • Posts

    8
  • Joined

  • Last visited

tsz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. now after i call the function I get only the last mysql row. function navigation(){ global $result, $db; $page_query = $db->query("SELECT * FROM `pages` "); if ($db->num_rows($page_query) > 0) { $output = ''; while($result = $db->fetch_array($page_query)){ $output = '<li> <a href="index.php?page='. $result['id'] .'">'.$result['name'].'</a> </li>'; } return $output; } }
  2. 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???
  3. I have tried too add the error reporting script. no related warnings to the class(only to another, unrelevent class). your second suggestion doesn't output anything either.
  4. I have tried but it doesn't work either.
  5. Soo I try to build an simple and basic template engine which displays content from template files. here is the class: class template { public $filename; public $assigned_vars = 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); } return $output; } else{ return "Missing template error"; } } } yet when I tries to execute the class its doesn't return anything. i execute it like this: $tp->display(ROOT_PATH.'home.php'); consider that I have defined ROOT_PATH already and $tp as new template class. what have i done wrong? help plz
  6. Hello, I recently installed Xampp and modified it's 80 and 443 default ports into other ports. I have also set an mysql password via the Xampp localhost manager. Now, I have rote an open_connection class in order to connect to the database but I get an credential error: Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\CMS\models\dbModel.php on line 19 failed to connect MYSQL Server. Please contact your website manager for futher assistance Here is the class I have wrote: what should i do? Is the problem in the class or in the configuration of XAMPP? Help plz. ty
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.