Reputation: 166
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;
}
Upvotes: 0
Views: 91
Reputation: 1371
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;
}
Upvotes: 0
Reputation:
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;
Upvotes: 0