dongqiao9015 2017-06-02 07:02
浏览 30
已采纳

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

thats my SQL Query

$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();

How to compare values from database with array comes from html in my code

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

getting results from database

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

binding the results

$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 ) {

Here i want to compare $cat with database values $Seats But

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

1条回答 默认 最新

  • dtq81142 2017-06-02 07:33
    关注

    It seems like you have the same event_id so you could use a query like

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 改进Yolov8时添加的注意力模块在task.py里检测不到
  • ¥50 高维数据处理方法求指导
  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错
  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?