In php, when we write and execute a query, we use while loop to iterate
$sql = "SELECT username, role FROM studentlogin WHERE username = '$username' and password = '$password'";
$res = mysql_query($sql);
while($row = mysql_fetch_array($res, MYSQL_NUM)){
$uname = $row[0];
$stud_role = $row[1];
}
We then use variables $uname and $stud_role somewhere in our code. I'm trying to do something similar in codeigniter but it fails.
function studentlogin($username, $password)
{
$query = "SELECT username, role FROM studentlogin WHERE username = ? and password = ?";
$result = $this->db->query($query, array($username, $password));
if($result->num_rows() == 1)
{
return $result;
}
else
{
return false;
}
}
I'm calling this function from controller as follows
$data['info'] = $this->student_model->stdentlogin($username, $password);
Here comes the problem. I've tried using the same while loop as above, but it doesn't work here. How can i access each of the two values separately in controller? Need some help.