删除相同的获取数据的PHP

时间:2018-07-21 15:15:26

标签: php mysql

#include <iostream>
#include <chrono>

using namespace std::chrono;
int main() {
  auto start = system_clock::now();
  while (duration_cast<seconds>(system_clock::now() - start).count() < 5)
    ;
  // It is now 5 seconds later.
}

如何消除相同的提取数据并仅回显一个?谢谢

这是它所呼应的那个。应该是它只会回声一个,因为它是相同的enter image description here

我在这里想要做的是在学校里感谢mos违反了规则

1 个答案:

答案 0 :(得分:0)

如果您希望所有违规行为从最严重到最不严重

$s_stud = $con->query("SELECT violation_type, count(violation_type) as num_violations
                      FROM violations_tbl 
                      GROUP BY violation_type
                      ORDER BY num_violations DESC");

while($row= $s_stud->fetch_assoc() ){
    //echo the violation and the count
    if($row['num_violations'] > 1 ){
        echo "<tr>";
        echo "<td>$row[violation_type]</td>";
        echo "<td>$row[num_violations]</td>";
        echo "</tr>";
    }
}

如果只希望违反MOST,则可以在查询中添加LIMIT 1并删除循环。

$s_stud = $con->query("SELECT violation_type, count(violation_type) as num_violations
                      FROM violations_tbl 
                      GROUP BY violation_type
                      ORDER BY num_violations DESC
                      LIMIT 1");

$row= $s_stud->fetch_assoc();
//echo the violation and the count
echo "<tr>";
echo "<td>$row[violation_type]</td>";
echo "<td>$row[num_violations]</td>";
echo "</td></tr>";