I have a MYSQL query the goes through a framework (WolfCMS).
$sql_query = 'SELECT DISTINCT country FROM ' . $tableName . ' ORDER BY country ASC';
$countries = Record::query($sql_query, array()); //execute query
But what is returned is an array of objects like this
Array ( [0] => stdClass Object (
[country] => Canada ) [1] => stdClass Object (
[country] => France ) )
I was wondering if there was a way with php to merge all the object to get the array as simple as possible like
Array ( [0] => Canada [1] => France )
I know I could always parse the array with a foreach
loop once I get the data and create a custom array the way I needed but I was wondering if there was a way to directly get the data to it's final form from the database.
I just want a simple array to use it as an parameter for an autocomplete function on a text field.
* EDIT *
I found a better way. I simply had to avoid executing the query with the Record class.
Here's how
//create sql statement
$sql_query = 'SELECT DISTINCT country' .
' FROM ' . Record::tableNameFromClassName(__CLASS__) .
' ORDER BY country ASC';
$stmt = Record::getConnection()->prepare($sql_query);
$stmt->execute(array());
return $stmt->fetchAll(Record::FETCH_COLUMN);