Duwi irwanto Duwi irwanto - 7 months ago 10
PHP Question

Displays the value but the result into an array

I am trying to retrieve data from a database by using multiple where when I call on Views of data actually appears letters array? What is wrong?

Models

function produk() {
$sql = "SELECT penjualan * jumlah FROM toko
WHERE toko = 'ALFA' AND produk = 'susu'";

return $this->db->query($sql)->result();

}


Controllers

public function index() {
$data=array('produk' =>$this->m_ff->produk(),
'isi' =>'home/v_ff'
);
$this->load->view('layout/wrapper',$data);
}


Views

<?php echo produk; ?>

Answer

make sure you column name are correct

Need to change your query to

  SELECT * FROM toko             
            WHERE toko = 'ALFA' AND produk = 'susu'

If you want to multiply two colunm Using Active record then use it as

 $this->db->select("`penjualan`*`jumlah` as multiply", FAlSE);// for multiplication of two column
   $this->db->where("toko","ALFA");
   $this->db->where("produk","susu");
   $query=$this->db->get('toko');
   $ret = $query->row();// for single row
   return $ret->multiply;

And in View you get your data as

<?php echo $produk); ?>
Comments