dongzuo4666 2016-07-11 06:12
浏览 38

如何使用PHP和MySQL中的任何字符从表中搜索

I have an issue. I am searching the data from table by giving the letter as input using PHP and MySQL.Here i am facing some issue while searching. I am explaining my code below.

$searchKey=$_GET['searchKey'];
$keyword = $searchKey.'%';
$sql =mysqli_query($connect,"SELECT * FROM  db_restaurant_basic WHERE rest_name LIKE '".$keyword."' and special='".$special_id."' and city='".$city_id."' and status=1 ORDER BY member_id DESC ");

Here if can putting the direct name then search functionality can work. Suppose I have one rest_name The Joyce and I want to search this. When user is putting the name directly like The Joyce or The then its working but if user is searching like this Joyce only its not working but it should work. Similarly there is a another rest_name Toad 'n' Turtle. If user will put Toad or 'n' or Turtle it should work which is not working in my current case. Please help me to resolve this issue.

  • 写回答

1条回答 默认 最新

  • drvc63490 2016-07-11 06:27
    关注
    $keyword = $searchKey.'%';
    

    In this case it will search only the word starting with "$keyword"

    $keyword = '%'.$searchKey;
    

    In this case it will search only the word ending with "$keyword"

    If you want to select all the words which contains "$keyword" you have to change your searchKey to

    $keyword = '%'.$searchKey.'%';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么