I’ve got the following function in a model, however it keep returning:
Message: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
And I for the life of me can’t figure out why.
function getNames() {
$query1 = $this->db->query("SELECT * FROM Device_tbl ORDER BY Manufacturer");
$dev = array();
while($row = mysql_fetch_array($query1))
{
$manu = $row['Manufacturer'];
$mod = $row['Model'];
$dev[] = $manu.' '.$mod;
}
return $dev->result();
}
Can anyone help?
Answer for CodeIgniter is:
$query1 = $this->db->query("SELECT * FROM table");
foreach($query1->result_array() as $row)
{
$manu = $row['column1'];
$mod = $row['column2'];
echo $manu.' '.$mod;
}
return $query1->result();
The problem is you’re mixing CodeIgniter database methods with built in PHP database methods.
mysql_fetch_arrayexpects a resource, not a CI query object.Check out the docs on fetching results.