I'm trying to get data fom a database, the problem is that I get a notice 'Array to string conversion'
, and $array
returns 'Array'. the get_rows
method gets all the rows using the current query. Any idea why this is happening? here's the code:
public function load_seat_by_number($seat_number)
{
$db = model_database::instance();
$sql = "SELECT * FROM `seats` WHERE `seat_number` = '". intval($this->seat_number). "'";
if (($array = $db->get_rows($sql)) > 0)
return $array;
else return FALSE;
}
This happens because $array is, well, an array. Use count instead. Otherwise, check your database model to see if there is a way to get the number of rows from the result.
$array = $db->get_rows($sql);
if(count($array) > 0)
Use sizeof
or count
to get the number of elements in an array.
if (($array = sizeof($db->get_rows($sql))) > 0) //returns the integer value(total no. of elements in an array)
return $array;
or
if (($array = count($db->get_rows($sql))) > 0) //returns the integer value(total no. of elements in an array)
return $array;
This should work
public function load_seat_by_number($seat_number)
{
$db = model_database::instance();
$sql = "SELECT * FROM `seats` WHERE `seat_number` = '". intval($this->seat_number). "'";
if (count($db->get_rows($sql)) > 0)
return $db->get_rows($sql);
else return FALSE;
}