dongqiao9015 2017-06-01 23: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-01 23: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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部