gpt4 book ai didi

php - 使用多个变量进行 Like 查询。请帮助我缩短查询时间

转载 作者:行者123 更新时间:2023-11-29 10:47:20 25 4
gpt4 key购买 nike

这就是我的 SQL 查询

$stmt = $con->prepare("select * from fistevent WHERE  row_name LIKE 'A%' And Event_Id =? OR row_name LIKE 'B%' And Event_Id =? OR row_name LIKE 'C%' And Event_Id =? OR row_name LIKE 'D%' And Event_Id =? OR row_name LIKE 'E%' And Event_Id =? order by row_name ASC");
$stmt->bind_param("s", $_POST['EventId']);
$stmt->execute();
$result = $stmt->get_result();

如何将数据库中的值与代码中来自 html 的数组进行比较

$TicketType =$_POST['Tickettype'];
$seatS=$_POST['finalSeats'];
$EventId=$_POST["Eventid"];
$sqlData = array();

从数据库获取结果

$stmt = $con->prepare("SELECT * FROM fist WHERE `Id`=? AND `Type`=?") or die($con->error);

绑定(bind)结果

$stmt->bind_param("ss",$EventId , $TicketType);
$stmt->execute();
$stmt->store_result();
$stmt-> bind_result($id,$Event_Id,$TicketType,$seats);
if($stmt->fetch())
{
$data[] = array($id,$Event_Id,$TicketType,$seats);
$Tickettype=$TicketType;
$Rowname=$row_name;
$Seats=$seats;
$cats = array_filter(array_map('trim', explode(',', $seatS)));
foreach($cats as $key => $cat ) {

这里我想将 $cat 与数据库值 $Seats But 进行比较

while($Seats==$cat)
{
echo "already hold";
}
else
{
echo "hold the seats";
}
}
}

最佳答案

看来您有相同的 event_id,因此您可以使用类似的查询

select * from fistevent WHERE (row_name LIKE 'A%' OR row_name LIKE 'B%' OR row_name LIKE 'C%' OR row_name LIKE 'D%' OR row_name LIKE 'E%') And Event_Id =? order by row_name ASC

关于php - 使用多个变量进行 Like 查询。请帮助我缩短查询时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44322752/

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