在php中,如何退出if条件不在while循环中?

在php中,如何退出if条件不在while循环中?,php,Php,如何退出if条件不在while循环?当国家/地区与当时存储的国家/地区匹配时,退出if条件不在while循环 $country = $_POST['Country'] ; $sql = "select * from country_details"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { $AllCountry = $row['Cou

如何退出if条件不在while循环?当国家/地区与当时存储的国家/地区匹配时,退出if条件不在while循环

    $country = $_POST['Country'] ;
    $sql = "select * from country_details";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result))
    {
         $AllCountry = $row['CountryName']; 

         if($country==$AllCountry)
         {

            $Last_Insert_Country_Id=$row['CountryId'];
            break;

         }
         else
         {

            $date = date("Y/m/d");
            $sql = "insert into country_details (CountryName,CreatedDate) values ('$country','$date')";
            $query=mysql_query($sql);
            $Last_Insert_Country_Id=mysql_insert_id();
            break;
          }


  }

使用continue进入当前周期的末尾,开始新的while迭代


使用break退出当前while循环。

if
语句条件匹配时,您的
break
除了跳出循环外什么也不做。因此,通过询问“中断if语句”是多余的。如果要跳过循环迭代的其余部分,请改用
continue
,但这似乎是不必要的:

当if触发时,else不会触发。因此,无论哪种方式,迭代都将被跳过


哦,请清理你的输入。您容易受到SQL注入的攻击!MYSQL_*也不推荐使用,请使用MYSQLi_*或PDO。

尝试
继续
而不是中断退出if条件是什么意思。是否要进行下一次迭代。?在if/之后暂停,您没有任何命令,因此我认为没有必要使用继续。