gpt4 book ai didi

php - 我可以在 SQL 中使用 AND 运算符 2 次吗?

转载 作者:行者123 更新时间:2023-11-29 16:23:52 27 4
gpt4 key购买 nike

所以我已经尝试了一周,在我选择日期的提交按钮后,表内的值丢失了

所以当进入这个页面时会显示

'SELECT * FROM attendance WHERE lect_id = 'CS0198289' AND dateofupdate LIKE '%0%' AND codeofsubject = 'CSNB214' ORDER BY studname ASC'

它将显示我的 lect_id、dateofupdate=0 和主题代码。当我选择提交(选择)按钮时,它会变成

'SELECT * FROM attendance WHERE lect_id = 'CS0198289' AND dateofupdate LIKE '%2019-01-23%' AND codeofsubject = '' ORDER BY studname ASC'

那么有人可以帮助我吗?非常感谢

<?php
$connect = mysqli_connect ("localhost","root","","ubas")
or die("Cannot connect to server".mysqli_error($connect));

if (!isset($_POST['dates'])){
$_POST['dates']=0;
}
$id = @$_POST["lect_id"];
$codeofsubject = @$_POST['code'];

$display = "SELECT * FROM attendance WHERE lect_id = '$_SESSION[id]' AND dateofupdate LIKE '%".$_POST['dates']."%'
AND codeofsubject = '$codeofsubject' ORDER BY studname ASC";
echo $display;
$result = mysqli_query ($connect,$display)
or die ("Cannot view due to".mysqi_error($connect));

echo"<form role='form' method='post'>
<div class='form-group'>
<label>Date</label>
<input style='width:180px; display:inline' class='form-control' type='date' name='dates' id='dates'>
<button type='submit' style='display:inline' name='select'>Select</button>
</div>
</form>";

echo"
<form method = post action = updateattend.php>
<table width='100%' class='table table-striped table-bordered table-hover' id='dataTables-example'>
<thead>
<tr>
<th><center>Date</center></th>
<th><center>Student Name</center></th>
<th><center>Student ID</center></th>
<th><center>View</center></th>
<th><center>Attend Status</center></th>
</tr>
</thead>";
while($row = mysqli_fetch_array($result,MYSQLI_NUM))
{
$attendid = $row [0];
$studname = $row [1];
$studid = $row [2];
$lect_id = $row [3];
$codeofsubject = $row [4];
$date = $row [5];
$dateofenroll = $row [6];
$attendstatus = $row [7];

echo"<tbody>
<tr>
<td><center>$date</center></td>
<td><center>$studname</center></td>
<td><center>$studid</center></td>
<td align = center>
<a class ='btn-warning btn' href ='updatestud.php?id=".$row['2']."'>VIEW</a>
</td>";
echo"

<td align = center>
<select class = 'form-control' name = 'attendstatus[]'>
<option value='$attendstatus' selected>$attendstatus</option>";

if($attendstatus =="Attend")
{
echo "<option value='Not Attending'>Not Attending</option>
<option value='Not Attending with Reason'>Not Attending with Reason</option>";
}
elseif ($attendstatus =="Not Attending") {
echo"<option value='Attend'>Attend</option>
<option value='Not Attending with Reason'>Not Attending with Reason</option>";
}
else{
echo"<option value='Attend'>Attend</option>
<option value='Not Attending'>Not Attending</option>";
}

echo"</select>
</td>
</tr>
</tbody>";
}

?>
</table>

最佳答案

SQL 语句中的 AND 运算符没有限制。您可以根据需要使用任意多个 AND,但您的逻辑在 SQL 语句的意义上应该是正确的。

例如

SELECT something FROM something WHERE something=something AND something=something AND something=something AND something=something;

因此,something=something 部分成为一个单独的逻辑语句,基于 AND 与其他 something=something 语句分开评估运算符(operator)。但请记住,上面的整个声明只是一个声明。

关于php - 我可以在 SQL 中使用 AND 运算符 2 次吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54377237/

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