在这种情况下如何使用comaprision

时间:2017-04-14 13:18:34

标签: php mysql string-comparison

如果(isset($ _ POST ["请求"])){

  $email = $_POST['email'];
  $p_name = $_POST['p_name'];
  $noc = $_POST['noc'];
  $year = $_POST['year'];


  $get_email = "select email from book where email = '$email' ";
  $run_email = mysqli_query($con,$get_email);
  $check = mysqli_num_rows($run_email);

  if($check==1){

    echo "<script>alert('You Have Already Booked') </script>";
    exit();
  }

    $get_name = "SELECT capacity from party where type_party='$p_name' ";
    $run_name = mysqli_query($con,$get_name);
    $checkk = $run_name > '$noc';

  if(checkk){

    echo "<script>alert('Out Of Bound') </script>";
    exit();
    }

如何比较派对表的容量与$ noc的值? 请帮帮我。谢谢!

2 个答案:

答案 0 :(得分:0)

您在上一个条件中错过了$

<?php
  $email = $_POST['email'];
  $p_name = $_POST['p_name'];
  $noc = $_POST['noc'];
  $year = $_POST['year'];


  $get_email = "select email from book where email = '$email' ";
  $run_email = mysqli_query($con,$get_email);
  $check = mysqli_num_rows($run_email);

  if($check==1){

    echo "<script>alert('You Have Already Booked') </script>";
    exit();
  }

    $get_name = "SELECT capacity from party where type_party='$p_name' ";
    $run_name = mysqli_query($con,$get_name);
    $checkname = mysqli_num_rows($run_name );
    //$checkk = $run_name > '$noc';

  if($checkname > $noc){

    echo "<script>alert('Out Of Bound') </script>";
    exit();
    }
?>

答案 1 :(得分:0)

只需更改下面的代码即可。

$get_name = "SELECT capacity from party where type_party='$p_name' ";
$run_name = mysqli_query($con,$get_name);
$row_cnt = mysqli_num_rows($run_name);
$rows = mysqli_fetch_assoc($run_name );

// please use any one condition which meet your requirement.
$checkk = $run_name > $noc;
// or
$checkk = $rows['capacity'] > $noc; 
// if it's not working try below
$checkk = $rows[0]['capacity'] > $noc;


if($checkk){
    echo "<script>alert('Out Of Bound') </script>";
    exit();
}

我使用&#34; mysqli_num_rows&#34;获取查询中找到的结果数量。然后与$ noc进行比较以获得正确的结果。或者使用第二个条件将$ noc与&#34; $ run_name [&#39; capacity&#39;]&#34;进行比较。