2016-11-15 8 views
0

私はここにいくつかの問題がありますクエリの1つがPHP MySQLのデータの範囲内にあるかどうかをチェックする方法?

入力のいずれかを確認する方法はデータの範囲ですか?両方のデータは、両方のデータがデータ

の範囲の間にある同じ値またはを持っている場合は、最初のだけで実行した場合でも、データのいずれかが範囲であれば、それは実行されません。

私の質問は、入力のいずれかが範囲内にあるかどうかを確認する方法ですか?

次のようにコード:

<?php 
    $connect  = mysqli_connect("", "root", "", ""); 
    global $connect; 

    if(isset($_POST['Submit'])){ 
     $time_out = $_POST['time_out']; 
     $time_enter = $_POST['time_enter']; 

     $sql = "SELECT * FROM table"; 
     $get = mysqli_query($connect,$sql); 
     if($get && mysqli_num_rows($get) > 0){    
      while($row = mysqli_fetch_assoc($get)){ 

      $time_out_db = $row['time_out']; 
      $time_enter_db = $row['time_enter']; 

       if(($time_out >= $time_out_db) && ($time_enter <= $time_enter_db)) 
       { 
        echo "Time is in between"; 
       } 
       else if(){ 
        echo "Either one of the time_out or time_enter is in the range"; 
       } 
      } 
      mysqli_free_result($get);   
     }else{ 
      echo "Nothin here !"; 
     } 
    } 
?> 
<form action="time.php" method="post"> 
    <table> 
     <tr> 
      <td><i class="fa fa-unlock-alt"></i> </td> 
      <td>Time out : </td> 
      <td><input type ="text" name="time_out" size="30"></td> 
     </tr> 
     <tr> 
      <td><i class="fa fa-unlock-alt"></i> </td> 
      <td>Time enter : </td> 
      <td><input type ="text" name="time_enter" size="30"></td> 
     </tr> 
    </table>  

    <p><input class="btnSuccess" type ="submit" name="Submit" value="Submit"> </p>    
</form> 

感謝。

+0

ORをurクエリで変更してください! – Soheyl

+0

既に行っていますが、それ以外の入力を実行できません:) – Jamilah

+1

ORでの過去のurクエリpls :) – Soheyl

答えて

0

は、2番目のifor||)条件を使用します。

<?php 
    $connect  = mysqli_connect("", "root", "", ""); 
    global $connect; 

    if(isset($_POST['Submit'])){ 
     $time_out = $_POST['time_out']; 
     $time_enter = $_POST['time_enter']; 

     $sql = "SELECT * FROM table"; 
     $get = mysqli_query($connect,$sql); 
     if($get && mysqli_num_rows($get) > 0){    
      while($row = mysqli_fetch_assoc($get)){ 

      $time_out_db = $row['time_out']; 
      $time_enter_db = $row['time_enter']; 

       if(($time_out >= $time_out_db) && ($time_enter <= $time_enter_db)) 
       { 
        echo "Time is in between"; 
       } 
       else if (($time_out >= $time_out_db) || ($time_enter <= $time_enter_db)){ 
        echo "Either one of the time_out or time_enter is in the range"; 
       } 
      } 
      mysqli_free_result($get);   
     }else{ 
      echo "Nothin here !"; 
     } 
    } 
?> 
<form action="time.php" method="post"> 
    <table> 
     <tr> 
      <td><i class="fa fa-unlock-alt"></i> </td> 
      <td>Time out : </td> 
      <td><input type ="text" name="time_out" size="30"></td> 
     </tr> 
     <tr> 
      <td><i class="fa fa-unlock-alt"></i> </td> 
      <td>Time enter : </td> 
      <td><input type ="text" name="time_enter" size="30"></td> 
     </tr> 
    </table>  

    <p><input class="btnSuccess" type ="submit" name="Submit" value="Submit"> </p>    
</form> 
+0

すでに試しました。それは働いていない – Jamilah

+0

私の悪い。それは魅力のように働いています。お返事ありがとう – Jamilah

+0

@ジャミラは知っておいて、それはあなたを助けてうれしいです:) – Veve

0

以下のコードを試してみてください。

if(($time_out_db>=$time_out) && ($time_enter<=$time_enter_db)){ 
    echo "Time is in between" 
}elseif(($time_out_db>=$time_out) || ($time_enter<=$time_enter_db)){ 
    echo "Either one of the time_out or time_enter is in the range"; 
} 
+0

すでに試してみました。それは動作していない – Jamilah

+0

私の悪い。それは魅力のように働いています。ありがとう – Jamilah

関連する問題