comma separator using implode not working

Trojan

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:

result: 14321 should be: 14,321

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);
Denis Bhojvani

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Laravel storing array using implode to DB not working

From Dev

Using comma as a list separator in Angular 2

From Dev

Using comma as list separator with StringTemplate 4

From Dev

Replace Text into image tag using comma separator

From Dev

Implode or join multidimentional array with comma

From Dev

Implode or join multidimentional array with comma

From Dev

Python regex for number with or without decimals using a dot or comma as separator?

From Dev

how to get the data using comma separator from mysql

From Dev

how to get the data using comma separator from mysql

From Dev

Path not working; using File.separator

From Dev

Implode() not Working in While Loop

From Dev

Filter implode title and separator string wordpress

From Dev

Is comma (,) operator or separator in Java?

From Dev

Is comma (,) operator or separator in Java?

From Dev

PHP implode function not working right

From Dev

php implode not working with sql oracle

From Dev

Implode function suddenly stopped working

From Dev

How to change position of data columns using regex in a CSV file using comma as separator?

From Dev

Masked EditText with comma as decimal separator

From Dev

seq uses comma as decimal separator

From Dev

Include a comma separator for data labels

From Dev

Add comma separator to axis labels

From Dev

include comma separator in javascript for loop

From Dev

dot instead of comma as thousand separator

From Dev

How to make a efficient comma separator

From Dev

retrieve and print values after comma separator from single field using join (codeigniter)

From Dev

Creating character vector with comma separator and without double quotes in R using paste command

From Dev

Separator insets not working

From Dev

PHP array in table using implode()

Related Related

  1. 1

    Laravel storing array using implode to DB not working

  2. 2

    Using comma as a list separator in Angular 2

  3. 3

    Using comma as list separator with StringTemplate 4

  4. 4

    Replace Text into image tag using comma separator

  5. 5

    Implode or join multidimentional array with comma

  6. 6

    Implode or join multidimentional array with comma

  7. 7

    Python regex for number with or without decimals using a dot or comma as separator?

  8. 8

    how to get the data using comma separator from mysql

  9. 9

    how to get the data using comma separator from mysql

  10. 10

    Path not working; using File.separator

  11. 11

    Implode() not Working in While Loop

  12. 12

    Filter implode title and separator string wordpress

  13. 13

    Is comma (,) operator or separator in Java?

  14. 14

    Is comma (,) operator or separator in Java?

  15. 15

    PHP implode function not working right

  16. 16

    php implode not working with sql oracle

  17. 17

    Implode function suddenly stopped working

  18. 18

    How to change position of data columns using regex in a CSV file using comma as separator?

  19. 19

    Masked EditText with comma as decimal separator

  20. 20

    seq uses comma as decimal separator

  21. 21

    Include a comma separator for data labels

  22. 22

    Add comma separator to axis labels

  23. 23

    include comma separator in javascript for loop

  24. 24

    dot instead of comma as thousand separator

  25. 25

    How to make a efficient comma separator

  26. 26

    retrieve and print values after comma separator from single field using join (codeigniter)

  27. 27

    Creating character vector with comma separator and without double quotes in R using paste command

  28. 28

    Separator insets not working

  29. 29

    PHP array in table using implode()

HotTag

Archive