我想知道以下是否可行,以及如何:
我想检查我的表格中的用户名是否显示在5行或更多行中
我的桌子:
我想要的用法示例:
如果名称(teste)超过5行,则执行某些操作..
答案 0 :(得分:2)
使用HAVING,它允许您按聚合/操作字段进行过滤
SELECT count(username) as shows_counter from tbl
group by username
HAVING count(username)>5
$check = mysql_query("SELECT count(name),name
FROM hack_log group by name HAVING count(name)>5");
$check = mysql_num_rows($result);// **Add this row**
if($check){ echo "HACKER!"; }else{ echo "not hacker"; }
您需要检查行数
$db = new PDO('mysql:host=your_hostname;dbname=your_db;charset=UTF-8', $user, $pass);
$q = $db->prepare('SELECT count(name),name
FROM hack_log group by name HAVING count(name)>5');
$q->execute();
$rows = $q->fetchAll();
$res= count($rows)>0?"Hacker":"No Hacker";
echo $res;