簡體   English   中英

如何從if條件不在PHP的while循環中退出?

[英]How to exit from the if condition not in while loop in 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['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;
          }


  }

如果滿足if語句條件,則break只會中斷循環。 因此,通過詢問“打破if語句”是多余的。 如果要跳過循環的其余部分,請改用continue ,但這似乎是不必要的:

如果if觸發,則else不會觸發。 因此,迭代將以任何一種方式被跳過。

哦,請清理您的輸入。 您容易受到SQL注入的攻擊! 不建議使用MYSQL_ *,請使用MYSQLi_ *或PDO。

繼續,您將轉到當前循環的結尾,並開始一個新的while迭代。

休息時退出當前循環。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM