-2

我正在寻求帮助,因为我尝试了几种选择,但最近没有成功。主要问题是结果表的标题始终显示,即使结果的值为“无结果”,我只想在没有表标题的情况下出现“无结果”消息。

if (preg_match("/^[  a-zA-Z]+/", $_POST['search'])) {     
    $name=$_POST['search']; 

    $sql="SELECT airport_id, airport_name, region_name, airport_code, island_name FROM airport, region, island WHERE airport_name LIKE '" . $name . "%' AND region_id=airport_region AND island_id=airport_island";   

    $result=mysql_query($sql); 
    $n=0;

    //* here is the table header with echo //should not be visible when $n=0
    while ($row=mysql_fetch_array($result)) {  
        $id_airport=$row['airport_id'];
        extract($row); 

        //*result of table when $n>=0 with the header of the table//
        ++$n;
    }

    if (0 == $n) {
        echo " no result ";
    }
}
4

1 回答 1

0
if (mysql_num_rows($result)){
    //there are results
    //echo tale header
    //also start while loop
while($row=mysql_fetch_array($result)){  



$id_airport=$row['airport_id'];

extract($row); 



}
}else{
 echo 'No result';
}
于 2013-02-11T21:32:40.607 回答