2014-10-11 3 views
0

에 존재 나는 그들이 스키를 탄 스키어와 스키 역이있는 테이블이없는 경우에만 표시 예를 들어는 MySQL의

:.

 
--------------------- 
    skier  station 
--------------------- 
| 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"}; 
} 

을하지만 그것은 작동하지 않습니다

나는 있습니다.

내가 표시 할 : 문이 거짓와 다른 문으로 이동한다면

 
Skier 1 
No here before, station 1 

답변

0

문제는 모든 반복이에 있습니다. 모든 가능성을 가진 어레이를 설정하고 그들이 해왔 던 방송국을 제거하면 결국에는 시청하지 못한 방송국 목록이 생깁니다.

또한 mysql_query 함수는 더 이상 사용되지 않으며 곧 PHP에서 제거 될 것이므로 사용해서는 안됩니다. 봐봐 mysqli. 또한 SQL Injection을 쿼리합니다. 귀하의 문제를 해결하기 위해 이러한 변경을하지 않았습니다.

$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"; 
}