Billy Adelphia Billy Adelphia - 3 months ago 15
MySQL Question

How to get result array from mysql in PHP

How to get result array from mysql in PHP ?
here is my code

$company = $_POST["company"];
$query = $this->db->query("Select id from users WHERE company like '$company'") ;
$user_id = mysqli_fetch_array($query,MYSQLI_ASSOC);
print_r ('$user_id');


here error message


Severity: Warning

Message: mysqli_fetch_array() expects parameter 1 to be mysqli_result,
object given


can anyone fix my code ??

Answer

Use codeigniter query builder:-

$company = $_POST["company"];
$query = $this->db->query("Select id from users WHERE company like '$company'") ;

foreach ($query->result() as $row)
{
    echo $row->available_fields;
}

Don't mix mysql with codeigniter query builder classes. Refer this link for better understanding https://www.codeigniter.com/userguide3/database/query_builder.html