如何计算列中的公共行并显示它们? [英] How to get a count of common rows in a column and display them?
本文介绍了如何计算列中的公共行并显示它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据库表,可以在报告用户时添加用户名。因为许多不同的用户可以报告一个用户,我想知道用户名在数据库表列中出现的次数,并在用户名旁边回显。
如果(count($ results)> 0){
/ / echo表
echo ' < table>';
echo ' < tr>< th>用户名< / th>< th>报告计数< / th>< / tr>';
$ rows = $ output - >使用fetchall();
foreach ($ rows as $ row){
$ username = $ row [' reportedUser'];
echo < tr> \ N跨度>;
echo < td>.$username. < / td>;
$ reportsQuery = SELECT reportedUser COUNT( *)AS count FROM duk_reports WHERE报告=:username;
$ reportsOutput = $ db-> prepare($ reportsQuery);
$ reportsOutput-> bindParam(' :username',$ username);
$ success = $ reportsOutput-> execute();
echo < td>.$reportsOutput[' count']。 < / td>;
echo < / tr> 跨度>;
}
}
我试过这个,但这不起作用。我接近让这个工作吗?
任何帮助非常感谢!
解决方案
results)> ; 0){
// echo table
echo ' < table>';
echo ' < tr>< th>用户名< / th>< th>报告计数< / th>< / tr>';
rows =
< blockquote>输出 - >使用fetchall();
foreach (
Hi,
I have a DB table that adds a username when a user is reported. Because many different users can report one user, I want to get a count of how many times the username appears in the database table column and echo it next to their username.
if (count($results) > 0){
//echo table
echo '<table>';
echo '<tr><th>Username</th><th>Reports count</th></tr>';
$rows = $output -> fetchAll();
foreach ($rows as $row){
$username = $row['reportedUser'];
echo "<tr>\n";
echo "<td>".$username."</td>";
$reportsQuery = "SELECT reportedUser COUNT(*) AS count FROM duk_reports WHERE reported = :username";
$reportsOutput = $db->prepare($reportsQuery);
$reportsOutput->bindParam(':username', $username);
$success = $reportsOutput->execute();
echo "<td>".$reportsOutput['count']."</td>";
echo "</tr>";
}
}
I tried this but this doesnt work. Am I close to getting this to work?
Any help greatly appreciated!
解决方案
results) > 0){ //echo table echo '<table>'; echo '<tr><th>Username</th><th>Reports count</th></tr>';
rows =
output -> fetchAll(); foreach (
这篇关于如何计算列中的公共行并显示它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文