SQL:
SELECT cast(user_id AS varchar(255)) AS member_id FROM cabinet
PHP:
$listData = array("member_id" => $row['member_id']);
Basically, you forgot to name the cast function's return in your SQL and used some extremely weird syntax in your PHP. $Array[] = $x;
adds element $x
as an array item to $Array
in PHP. To create a new array, you should run $Array = array();
. Some programming languages do indeed force you to put square brackets after a variable's name on value assignation to specify it as an Array/String type, but PHP is not one of them.
To reference an item by key, you have to use the array's name and the key's value in square brackets ($Array[$n]
, where $n
is an integer for arrays with integer indexes, and Array['key']
for arrays with String indexes). 'cast(user_id AS varchar(255))'
is not a valid array key, you have to give the SQL function return value a name to be able to reference it as an array item.
Please let me know if this makes sense.
My answer assumes that you are familiar with mySQLi
and know how to get $row['member_id']
from the query.