php - codeigniter won't show anything from my producten table -
could take , help me please.
model:<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class model_product extends ci_model { public function getall() { $results = $this->db->get('producten'); homecoming $results->result_array(); } }
controller: <?php if ( ! defined('basepath')) exit('no direct script access allowed'); class welcome extends ci_controller { public function index() { $this->load->model('model_product'); $data['products'] = $this->model_product->getall(); $this->load->view('header'); $this->load->view('welcome_message', $data); $this->load->view('footer'); } }
view: <table class="table"> <thead> <th>naam</th> <th>beschrijving</th> <th>prijs</th> <th>vooraad</th> <th>categorie</th> </thead> <tbody> <?php foreach ($products $product) { ?> <tr> <td><?php echo $product['naam']; ?></td> <td><?php echo $product['beschrijving']; ?></td> <td><?php echo $product['prijs']; ?></td> <td><?php echo $product['producten_op_voorraad']; ?></td> <td><?php echo $product['categorie_naam']; ?></td> </tr> <?php } ?> </tbody> </table>
there 1 row in right table "producten" database loaded. don't know do. can help me solve this?
try
model
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class model_product extends ci_model { function __construct() { // initialization of class parent::__construct(); } public function getall() { $results = $this->db->get('producten'); homecoming $results->result_array(); } }
controller
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class welcome extends ci_controller { function __construct() { // initialization of class parent::__construct(); $this->load->model('model_product'); } public function index() { $data['products'] = $this->model_product->getall(); $this->load->view('header'); $this->load->view('welcome_message', $data); $this->load->view('footer'); } }
and in autoload.php
$autoload['libraries'] = array('database');
php database codeigniter echo
No comments:
Post a Comment