我想查找我的表中是否有任何重复的票号。我下面的代码显示了类表中的第一个票号,即 1039,如果有重复,我想显示。1039 不是重复的。我的问题是什么?
$query = "SELECT ticket, COUNT(ticket) AS NumOccurrences FROM classes GROUP BY ticket HAVING (COUNT(ticket) > 1)";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$ticket = $row['ticket'];
}
if($result)
{
echo $ticket. "<br/>";
echo "there are " . mysql_num_rows($result) . " tickets ";
}
else
{
echo "no duplicate ";
}