i have a query getting the result inside my database and i'm using implode to get the result i want, my query is getting the sum of a column, the fetching works fine the only problem is that it shows me like this:
can somebody please help with it..
here is my code:
$res1 = $DB_con->query("SELECT sum(user_id) AS total FROM login");
$row = $res1->fetch(PDO::FETCH_ASSOC);
echo implode(',', $row);
I think here you don't need to used implode you can do like this way also.
$res1 = $DB_con->query("SELECT FORMAT((sum(user_id)),2) AS total FROM login"); $row = $res1->fetch(PDO::FETCH_ASSOC); echo $row['total'];
You need to use format function of MySQL. More About format function
Here Is The Explanation why there is no need to used implode function.
Implode function is used for convert each array value with convert into string with some specific delimiter Here as per your query you are getting single result sum so on that single value you can't used implode. You just need use format function for format your number as you want. More About implode function