dongwen2794 2012-06-16 21:56
浏览 34
已采纳

用PHP查询MySQL

I'm self teaching myself to do MySQL and PHP. It is a new world to me, i have a couple of books and i do a lot of research on google before asking here. So I'm stuck with the following problem and I can't find an answer, I have a MySQL database, the database has a specific field called URL.

Part of the URL field looks like this:

&path=products&user=Mark24&id=2616

currently i have it set up so people can search for items in the database, and that works great. what i want to be able to add to the search feature is search by user. as you can see the user is in the middle of the entire url so i have this:

    $query = "select Productid, Productname, url,  from Products where Productid like '%$keyword%' or Productname like '%$keyword%' or url like '%$keyword%' ";
    $result = mysqli_query($dbc,$query);

Now comes the real issue, ^^ this works wonders, people can actually search for the username and it will display exactly what i want. However if people search for the word "products" or "path" which is also in the url they will get over 2000 matches because every single url in my database has the word products and path. Why I want to avoid that? i don't want customers looking up our entire database, I'm also afraid of server overload because with each query a customer gets an image of the product, along with the product name and the link to the product. trying to load over 2000 pictures also slows down or crashes my browser, so i need to fix this somehow, but i'm not sure how to tackle it.

So is there a way to match only the part that says user="blah" for the URL field? do i do this with PHP, preg-match perhaps???

Any information provided is highly appreciated! Thanks.

  • 写回答

3条回答 默认 最新

  • donglongqiao9595 2012-06-16 22:10
    关注

    Try this instead:

    $query = "select Productid, Productname, url,  from Products where Productid like '%$keyword%' or Productname like '%$keyword%' or url like '%user=$keyword%' ";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序