I would like to get the amount of a MySQL-database, then I query "SELECT COUNT(*) FROM articles_table
" and got "[ RowDataPacket { 'COUNT(*)': 13 } ]"
I have tried to 'console.log(data[0].COUNT)', but I got a undefined message....
Could anyone tell me How do I do to get the number 13 with javascript?
Thank you very much!
I would like to get the amount of a MySQL-database, then I query "SELECT COUNT(*) FROM articles_table
" and got "[ RowDataPacket { 'COUNT(*)': 13 } ]"
I have tried to 'console.log(data[0].COUNT)', but I got a undefined message....
Could anyone tell me How do I do to get the number 13 with javascript?
Thank you very much!
Share Improve this question edited May 4, 2018 at 11:37 Sylvia asked May 4, 2018 at 11:19 SylviaSylvia 2772 gold badges6 silver badges16 bronze badges 4- You can store the value in php variable then just echo to the javascript variable. – Bibhudatta Sahoo Commented May 4, 2018 at 11:25
- possible duplication: stackoverflow./questions/31221980/… – Christian Felix Commented May 4, 2018 at 11:29
- I have tried to 'console.log(data[0].COUNT)', but I got a undefined message....@Christian Felix – Sylvia Commented May 4, 2018 at 11:34
- sorry...I know Javascript only@Bibhudatta Sahoo – Sylvia Commented May 4, 2018 at 11:41
1 Answer
Reset to default 4First, give the aliases to your expression column in SELECT statement i.e. for "COUNT(*)" as below.
SELECT COUNT(*) as cnt FROM articles_table
Then, try to use
console.log(data[0].cnt)