Okay, I'm new to this and have not got the lexicon mastered yet. Here's what I'm trying to do:
I've successfully read the data from my SQL with axios and in (f12) - network - preview. it shows:
successfully pushed as an array.
But in vue, when I try to display it. it shows: as
[ { "COUNT(`char_id`)": "1" } ]
How do I display ONLY the "1"?
my vue (inside ):
{{onlineUsers}}
(inside script)
data:() => ({
onlineUsers: [],
)},
created(){
this.onlineUsersFunction();
},
methods: {
onlineUsersFunction: function () {
axios.post(url, { switchCase: 2 }).then((response) => {
this.onlineUsers = response.data;
});
}
}
inside my crud.php
$switchCase = (isset($_POST['switchCase'])) ? $_POST['switchCase'] : '';
switch($switchCase){
case 1: //Select
$query = "SELECT * FROM login";
$stmt = $conn->prepare($query);
$stmt->execute();
$data=$stmt->fetchAll(PDO::FETCH_ASSOC);
break;
case 2:
$query = "SELECT COUNT(`char_id`) FROM `char` WHERE `online` = 1;";
$stmt = $conn->prepare($query);
$stmt->execute();
$data=$stmt->fetchAll(PDO::FETCH_ASSOC);
break;
}
print json_encode($data, JSON_UNESCAPED_UNICODE);
$conn = NULL;

char_id)"] }}fetchColumnafter changing the query toSELECT COUNT(`char_id`) as users_online FROM..