I have a mysql query like this:
$results = $wpdb->get_results($wpdb->prepare(
"
(SELECT
CAST(active AS SIGNED)
FROM $table_name
WHERE user_id = %d)
", $user_id
), ARRAY_A); // Output query as array
I then output the result with json_encode, however, the result is outputted like this:
{"CAST(active AS SIGNED)":"1"}
It shows the function name as column name and the value is still a string.
Any ideas what’s going on ? Thanks for your suggestions.
Try changing your SQL adding an “as” statement. Like this:
Then you can fetch your data using the name “column”.