由于这里没有要运行的代码,请查询 temptable 的城市和州,然后查询 SELECT COUNT(id) FROM permtable WHERE city='$tempcity' AND state='$tempstate'。
然后在您的查询中使用 mysqli_num_rows 以查看是否找到任何匹配项。
$q= "SELECT COUNT(*) FROM temptable WHERE city='$tempcity' AND state='$tempstate'";
$r = @mysqli_query($dbc, $q);
if(mysqli_num_rows($r) != 0) {
echo "<embed src =\"sound.wav\" hidden=\"true\" autostart=\"true\"></embed>";
}
else {
//Do your other stuff.
}
这真的取决于你如何设置你的桌子。如果您有“州”列和“城市”列,其中“城市”类似于“达拉斯-奥斯汀-胡斯廷-圣安东尼奥”,那么您将不得不查询“州”,将“城市”的值分解为一个数组,运行一段时间以检查数组中的 $tempcity,如下所示:
$q = "SELECT city FROM permtable WHERE state='$tempstate'";
$r = @mysqli_query($dbc, $q);
$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
if (mysqli_num_rows($r) == 1) { //STATE MATCH
$cityCheck = explode("-", $row['city']);
$i = 0;
$count = count($cityCheck);
$goodMatch = 0;
while ($i < $count) { //find out if user already voted on post
if ($cityCheck[$i] == $tempcity) {
$goodMatch = 1;
} //City State match
else { } //City does not match with state, continue while loop.
$i++;
} //END WHILE
else { } //STATE DID NOT MATCH
if ($goodmatch) {
echo "<embed src =\"sound.wav\" hidden=\"true\" autostart=\"true\"></embed>";
}
else {}