我在下面有这段代码,它为帖子选择所有 id,然后下面的代码片段查看是否有匹配项。如果匹配,则表示重复。我通过使用 print 命令打印 $test 和 print $unique 对其进行了测试,但它只显示一个 id 而不是所有 id。我该如何修复此代码,使其显示所有 id #,然后比较以查看是否存在重复,如果存在,它将显示“重复”。
$sql="SELECT `Post_id` from `posts`";
$result=mysql_query($sql);
$query = mysql_query($sql) or die ("Error: ".mysql_error());
if ($result == "")
{
echo "";
}
echo "";
$rows = mysql_num_rows($result);
if($rows == 0)
{
print("");
}
elseif($rows > 0)
{
while($row = mysql_fetch_array($query))
{
$storedid = htmlspecialchars($row['Note_id']);
print("");
}
}
//This $test id exists and $storedid should contain
3VRDY but it still goes through
$test = "3VRDY";
if ( $storedid == $test ) {
echo("duplicate");
die();
} else {
echo("");
}