I have php script and work:

 <?php
$con=mysqli_connect("localhost","root","","dbm");
// Check connection




if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();

  }

$result3 = mysqli_query($con,"select t.tgl_transaksi, p.kode_produk, tp.hp_tujuan, d.nama as nama2, sr.ket as ket2  from dbm.transaksi_psa tp
left join dbm.transaksi t
on tp.id_transaksi=t.id_transaksi
left join dbm.produk p
on tp.kode_produk = p.kode_produk
left join dbm.set_report sr on t.status=sr.jenis
left join dbm.distributor d on (tp.id_distributor=d.id_distributor and tp.com=d.com)
where date(t.tgl_transaksi)=date(now())
order by t.tgl_transaksi DESC");

echo "
<div class='table-responsive'>
<table class='table table-hover' id='t01'>
<tr>
<th>Tanggal</th>
<th>Produk</th>
<th>Tujuan</th>
<th>Suplier</th>
<th>Status</th>
</tr>";

while ($row = mysqli_fetch_array($result3))
  {
  echo "<tr>";
  echo "<td>" . $row['tgl_transaksi'] . "</td>";
  echo "<td>" . $row['kode_produk'] . "</td>";
  echo "<td>" . $row['hp_tujuan'] . "</td>";
  echo "<td>" . $row['nama2'] . "</td>";
  echo "<td>" . $row['ket2'] . "</td>";
  echo "</tr>";

  }
echo "</table></div> <br><br><br>";


mysqli_close($con);
?>

And I try change to Codeigniter MVC - OOP: Models:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Ikhtisar_model extends CI_Model{
     function __construct()
     {
          // Call the Model constructor
          parent::__construct();
     }

     //read the ikhtisar list from db
     public function get_all()
     {
         $this->db->select('t.tgl_transaksi AS tgl, p.kode_produk AS kode, tp.hp_tujuan AS nohp, d.nama AS nama2, sr.ket AS ket2', FALSE)
    ->from('transaksi_pulsa tp')
    //$this->db->where('date(t.tgl_transaksi)', 'date(now())');
    ->join('transaksi t','tp.id_transaksi=t.id_transaksi', 'left')
    ->join('produk p','tp.kode_produk = p.kode_produk', 'left')
    ->join('set_report sr','t.status=sr.jenis', 'left')
    ->join('distributor d','tp.id_distributor=d.id_distributor and tp.com=d.com', 'left')
    ->order_by("t.tgl_transaksi", "DESC");
    $ikhtisar = $this->db->get();
    //->result_array();

        //return $ikhtisar;


     }
}

Controllers:

<?php
if ( ! defined('BASEPATH')) exit('Akses di blok. Cek kembali link yang Anda tuju!');
 class ikhtisar extends CI_Controller {
     public function __construct()
     {
          parent::__construct();
          $this->load->helper('url');
          $this->load->database();
     }

     public function index()
     {
          //load the ikhtisar_model
          $this->load->model('ikhtisar_model');  
          //call the model function to get the ikhtisar data
          $ikhresult = $this->ikhtisar_model->get_all();           
          $data['ikhlist'] = $ikhresult;
          //load the ikhtisar_view
          $this->load->view('templates/header', $data);
          $this->load->view('ikhtisar_view',$data);
          $this->load->view('templates/footer', $data);
     }
}

Views:

<!-- BEGIN CONTENT -->
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12 col-sm-12">
                <table class="table table-striped table-hover">
                    <thead>
                    <tr>
                        <th>Tanggal</th>
                        <th>Produk</th>
                        <th>Tujuan</th>
                        <th>Suplier</th>
                        <th>Status</th>
                    </tr>
                    </thead>
                    <tbody>

                    <? foreach($ikhtisar->result_array() as $ikh): ?>
              <tr>
                <td><?=$ikhlist['tgl']?></td>
                <td><?=$ikhlist['kode']?></td>
                <td><?=$ikhlist['nohp']?></td>
                <td><?=$ikhlist['nama2']?></td>
                <td><?=$ikhlist['ket2']?></td>
              </tr>
              <? endforeach; ?>


                    </tbody>
                </table>
                </div>
            </div>
        </div>  
    </div>  

But, what I get, the data didn't display at all. The header, the footer, display correctly. Thanks for your help. I'm very beginner in PHP.

Related posts

Recent Viewed