php - Show database data with CodeIgniter -


i want show data in database codeigniter.

my code shows error 404 page requested not found.

model

<?php     class daftar_model extends ci_model      {         public function __construct()          {             //connect ke database             $this->load->database();         }          public function get_pertanyaan()         {             $query = $this->db->get('pertanyaan_ts');             return $query->result_array();         }      } ?> 

controller

<?php if ( ! defined('basepath')) exit('no direct script access allowed');  class daftar_controller extends ci_controller {      public function index()     {         //echo "hallo";         $this->load->model('administrator/pertanyaan/daftar_model');         $this->load->view('administrator/pertanyaan/daftar_view',$data);         $data["pertanyaan_ts"] = $this->daftarpertanyaan_model->get_pertanyaan;        } 

view

<html> <head>     <title><?php echo $judul; ?></title> </head> <body>     <h1>daftar user</h1>     <table border="1">         <thead>         <tr>             <th>pertanyaan</th>         </tr>     </thead>     <tbody>             <?php                 foreach($pertanyaan $p){         ?>                 <tr>             <td><?php echo $p->pertanyaan; ?></td>          </tr>            <?php } ?>     </tbody>     </table> </body> </html> 

a couple changes controller , should good.

change name of class , browse example.com/daftar

class daftar extends ci_controller {  public function index() {     //assign page title     $data['judaul'] = "daftar user";      $this->load->model('administrator/pertanyaan/daftar_model');      //you need assign value $data before sending view     $data["pertanyaan_ts"] = $this->daftar_model->get_pertanyaan;            $this->load->view('administrator/pertanyaan/daftar_view', $data); } 

your model returns array need access data sent view array syntax $p['pertanyaan_ts'] not object syntax $p->pertanyaan_ts. modified view file

<html>   <head>     <title><?php echo $judul; ?></title>   </head>   <body>     <h1>daftar user</h1>     <table border="1">       <thead>         <tr>           <th>pertanyaan</th>         </tr>       </thead>       <tbody>         <?php         foreach($pertanyaan_ts $p)         {           ?>           <tr>             <td><?php echo $p['pertanyaan']; ?></td>           </tr>           <?php         }         ?>       </tbody>     </table>   </body> </html> 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -