I'm investigating how to retrieve rows from database using Codeigniter and AJAX but it is not working, I followed the steps from here: How to get a row from database using ajax in codeigniter and nothing: here is what my code looks like:
table (user):
+----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+----------------+
| id_user | int(11) | NO | PRI | NULL | auto_increment |
| name | int(11) | YES | | NULL | |
| information | varchar(200) | YES | | NULL | |
+----------------+--------------+------+-----+---------+----------------+
controller (welcome.php):
function get_invoices()
{
$company = $_POST['pass'];
$this->login_select->get_login($company);//model
}
view(JQuery) once is loaded there is a form with one type text(named pass) and the other a submit:
function sendData(){
var data = $('form').serialize();
$('form').unbind('submit');
$.ajax({
url: '<?php echo base_url()?>index.php/welcome/get_invoices',
type: 'POST',
data: data,
success: function(data, textStatus, xhr) {
$('div#message').html(data);
}
});
}
the model (login_select.php) here is the problem:
public function get_login($myid)
{
$temp = array();
$this->db->select("user.*");
$query = $this->db->get_where('user', array('id_user'=>$myid));
$temp= $query->row_array();
echo $temp['name'];
//return $temp;
}
and finally I get:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: name
Filename: models/login_select.php
Line Number: 41
How to resolve this?, because I'm going to need to recover not just a row but the whole row from a table. Thanks