[eluser]Unknown[/eluser]
I am creating a site for my school about selling music, and created a function in CodeIgniter to add an entire album at once in the shopping cart, in theory should work but it only adds the last value in the array. How do I fix it? I put the code below:
function on cart.php
Code:
function addAlbum($id){ // Add o álbum completo ao carrinho
if($this->input->post('ajax')) {
$info = array();
$i = 0;
$query = $this->cart_model->pegarMusicas($id);
foreach($query->result() as $resultado) {
$info[$i]['id'] = $resultado->id_musica;
$info[$i]['qty'] = 1;
$info[$i]['price'] = $resultado->preco;
$info[$i]['name'] = $resultado->nome;
$i++;
}
if($this->cart->insert($info)){
$this->load->view("header");
} else {
return false;
}
} else {
print "Você não pode acessar essa página";
}
}
Model cart_model.php
Code:
function pegarMusicas($id){
$this->db->where('id_album', $id);
return $this->db->get('musicas');
}