仅在mysql中不存在时显示


Show only if not exist in mysql

我有一张桌子,里面有滑雪者和他们滑雪的滑雪站。

例如:

---------------------滑雪者站---------------------|1|2|1|3|2|2---------------------

如果我有三个站,我想显示一条文字,说滑雪者不在这个站。

我有:

 $result="SELECT * FROM skiers_and_stations WHERE skier = '$id_skier';";
 $makeResult=mysql_query($result, $conexion);
 while ($row = mysql_fetch_array($makeResult, MYSQL_ASSOC)) {
 if ($row['station'] == '1') {   } else {echo "No here before, station 1"}; 
 if ($row['station'] == '2') {   } else {echo "No here before, station 2"}; 
 if ($row['station'] == '3') {   } else {echo "No here before, station 3"}; 
 }

但它不起作用。

我想显示:

滑雪板1之前没有,1号站

问题是在每次迭代中,if语句中的两个将为false,并转到else语句。如果你设置了一个具有所有可能性的阵列,并删除他们去过的车站,最后你会得到他们没有去过的车站的列表。

此外,您真的不应该使用mysql_query函数,因为它们已被弃用,很快就会从PHP中删除。看看mysqli。此外,对查询执行SQL注入。为了解决你的问题,我没有做那些改变。

$result = "SELECT * FROM skiers_and_stations WHERE skier = '$id_skier';";
$makeResult = mysql_query($result, $conexion);
$stations = array(1 => true, 2 => true, 3 => true);
while ($row = mysql_fetch_array($makeResult, MYSQL_ASSOC)) {
    unset($stations[$row['station']]);
}
foreach ($stations as $stationId => $val) {
    echo "Not here before, station $stationId";
}