最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get a RowDataPacket object from MySQL? - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 4

First, 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)
发布评论

评论列表(0)

  1. 暂无评论