gpt4 book ai didi

php - 如何编写多个条件为 true 的 php If 语句(Condition#1=true、Condition#2=true、Condition#3=true)

转载 作者:行者123 更新时间:2023-11-29 15:25:58 27 4
gpt4 key购买 nike

我有一个包含 FromDate 、 ToDate 、 VendorName 和 GoodsName 的表单,一旦一切为真,我需要显示结果

示例: FromDate="11/20/2019"、ToDate="11/28/2019"、VendorName="Abdullah"和 GoodsName="Wheat",

这是我的代码

表单.php

<form method="post" action="purchase_report.php"  id="demo-form2" data-parsley-validate class="form-horizontal form-label-left">
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="date">From Date <span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" class="form-control has-feedback-left" name="start_Date" id="startDate">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="endDate">End Date</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" class="form-control has-feedback-left" name="end_Date" id="endDate">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="vendor-name">Vendor Name</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" class="form-control has-feedback-left" name="vendor_name" id="vendor-name">
</div>
</div>

<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="snack-name">Goods Name</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" class="form-control has-feedback-left" name="snack_name" id="snack-name">
</div>
</div>

<div class="ln_solid"></div>
<div class="form-group">
<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
<button type="submit" class="btn btn-success">Search</button>
<button class="btn btn-primary" type="reset">Reset</button>
</div>
</div>
</form>

purchase_report.php

$start_Date = mysqli_real_escape_string($con, $_POST['start_Date']);
$end_Date = mysqli_real_escape_string($con, $_POST['end_Date']);
$vendor_name = mysqli_real_escape_string($con, $_POST['vendor_name']);
$snack_name = mysqli_real_escape_string($con, $_POST['snack_name']);

if ( ($vendor_name == $vendor_name) &&
($snack_name == $snack_name) &&
($start_Date == $start_Date))
{
$sql = "SELECT *
FROM t_purchase
WHERE from_vendor ='$vendor_name'
AND goods_name ='$snack_name'
AND date BETWEEN '$start_Date' AND '$end_Date'";
$result = $con->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {

$data = '<tr><td>' .$row["id"]. '</td><td>' .$row["date"].
'</td><td>' .$row["goods_name"]. '</td><td>'
.$row["from_vendor"]. '</td><td>' .$row["no_kgs"].
'</td><td>' .$row["rate_of"]. '</td><td>'
.$row["bill_rate"]. '</td><td>' .$row["now_paid"].
'</td><td>' .$row["v_balance"]. '</td></tr>';
echo $data;
}
} else {
echo "0 results";
}
}

最佳答案

您需要更改 SQL 查询。
尝试此查询

$sql = "SELECT * 
FROM t_purchase
WHERE from_vendor ='".$vendor_name."'
AND goods_name ='".$snack_name."'
AND date BETWEEN '".$start_Date."'
AND '".$end_Date."'";

关于php - 如何编写多个条件为 true 的 php If 语句(Condition#1=true、Condition#2=true、Condition#3=true),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59092093/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com