php - MySQL returns 2 values for every field requested -
this question has answer here:
when doing query() select statement results contain 2 entries field.
$sql = "select first_name, last_name users"; $rslt = $conn->query($sql);
in example above, results contain 4 items in array. 2 incrementing integers key, 1 key set "first_name" , 1 key set "last_name".
array ( [first_name] => bill [0] => bill [last_name] => johnson [1] => johnson )
i'm sure stupid question, there quick way either change way results returned contains 1 key=>value each field or there way remove data?
what want final array 1 of 2 things...
required result 1
array ( [first_name] => bill [last_name] => johnson )
required result 2
array ( [0] => bill [1] => johnson )
thanks in advance.
if using pdo, can set fetch mode
$rslt = $conn->query($sql, pdo::fetch_assoc);
it defaults returning both types.
see http://php.net/manual/en/pdo.query.php more information