admin管理员组文章数量:1415111
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)
本文标签: javascriptHow to get a RowDataPacket object from MySQLStack Overflow
版权声明:本文标题:javascript - How to get a RowDataPacket object from MySQL? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745198212a2647241.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论