需要一些关于PHP代码的帮助吗

需要一些关于PHP代码的帮助吗,php,mysql,Php,Mysql,我需要一些帮助来获取每个用户的数据,并且需要从userid获取另一个表文章示例: 我有一个名为(tbl_用户)的用户表 我这张桌子上有文章(称为文章) 现在,我想在表文章中获得所有由userid发布的mysql\u num\u行,并将ok=3 error=3和total=6分开 例如: user=test totalarticles=3 postedok=1 postederror=2 user=claudia totalarticles=3 postedok=2 postederror=1

我需要一些帮助来获取每个用户的数据,并且需要从userid获取另一个表文章示例:

我有一个名为(tbl_用户)的用户表

我这张桌子上有文章(称为文章)

现在,我想在表文章中获得所有由userid发布的mysql\u num\u行,并将ok=3 error=3和total=6分开

例如:

user=test totalarticles=3 postedok=1 postederror=2
user=claudia  totalarticles=3 postedok=2 postederror=1

这将以resonalbe的速度为您提供所需的所有数据。有很多方法可以让数据爱好者了解,但这应该是最容易理解的方法。

你能展示一下你的尝试吗?我想指出的是,你格式化数据的方式确实很难阅读。@JonStirling idk how to explain:/我有两个表1:users 2st:userarticles。我想做一个关于用户的统计表。每个用户文章总数每个用户发表的文章都可以等等。@JamieBicknell我在google上发现了这个:但它确实有效。@BimiGjika循环每个用户,并运行一些SQL来获取统计数据的总数
articleid=5 postedby=(userid=2) title=(articles test1) description=(article test description1) posted(ok)
articleid=6 postedby=(userid=33) title=(articles test2) description=(article test description2) posted(error)
articleid=7 postedby=(userid=2) title=(articles test3) description=(article test description3) posted(error)
articleid=8 postedby=(userid=33) title=(articles test4) description=(article test description4) posted(ok)
articleid=9 postedby=(userid=2) title=(articles test5) description=(article test description5) posted(ok)
articleid=10 postedby=(userid=33) title=(articles test6) description=(article test description6) posted(error)
user=test totalarticles=3 postedok=1 postederror=2
user=claudia  totalarticles=3 postedok=2 postederror=1
SELECT username, 
  (SELECT COUNT(*) FROM articles a WHERE u.id = a.userid) as totalarticles,
  (SELECT COUNT(*) FROM articles a WHERE u.id = a.userid AND posted = 'ok') as postedok,
  (SELECT COUNT(*) FROM articles a WHERE u.id = a.userid AND posted = 'error') as postederror
FROM tbl_users u