Use alias in your query as follows
$query = $db->query("SELECT COUNT('user_id') as c FROM user_credentials WHERE email='$email'");
and fetch alias name... it will solve your problem...
Pregunta
So this is what my screen gives me
mysqli_result Object
(
[current_field] => 0
[field_count] => 1
[lengths] =>
[num_rows] => 1
[type] => 0
)
1
stdClass Object
(
[COUNT('user_id')] => 0
)
1
I'm trying to access the [COUNT('user_id')] part, but I can't seem to find out how on the internet. The code I'm using is:
$query = $db->query("SELECT COUNT('user_id') FROM user_credentials WHERE email='$email'");
echo "<pre>", print_r($query), "</pre>";
if($query->num_rows){
while($row = $query->fetch_object()){
echo "<pre>", print_r($row), "</pre><br />";
#echo "<h1>", $row->COUNT['user_id'], "</h1>";
}
}
Obviously the trouble is $row->COUNT['user_id'], but I don't know how to access that. It's not an array so I'm at a loss. I've just begun learning objects.
Solución
Use alias in your query as follows
$query = $db->query("SELECT COUNT('user_id') as c FROM user_credentials WHERE email='$email'");
and fetch alias name... it will solve your problem...