PHP在数据库中搜索多行 [英] PHP searching multiple rows in database

查看:68
本文介绍了PHP在数据库中搜索多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用PHP和MySQL从一个数据库中搜索多个列.目前我正在工作.

I am wanting to search more than column from one database with PHP and MySQL. Currently I have this working.

这是我的表格:

  <form action="products.php" method="POST">
  Search: <input type="text" name="search" />
  <input type="submit" value="submit"/>
  </form>

这是我当前的工作查询:

and here is my current working query:

$query = "SELECT * FROM `GraphicsCards` WHERE `Brand` LIKE '%". $search . "%'";
$run = mysqli_query ($connection, $query);

您可以看到我的查询正在搜索数据库,以查看输入的用户搜索是否与品牌"列中的任何内容匹配.

As you can see my query is searching my database to see if the user search entered matches anything in the column "Brand".

我还有其他列,例如型号",价格"等,并且希望能够搜索这些列以及品牌".是否可以通过一个查询来做到这一点?

I have other columns such as "Model" "Price" etc etc, and would like to be able to search those as well as just "Brand". Is it possible to do this is one query?

此外,我已经尝试过'AND'和'OR'以及'|| '但它们不起作用.

In addition I have already tried ' AND ' and ' OR ' and also ' || ' but they do not work.

推荐答案

OR将起作用,您只需要正确执行即可.

OR will work, you just have to do it correctly.

$query = "SELECT * FROM `GraphicsCards`
    WHERE `Brand` LIKE '%". $search . "%'
        OR `Model` LIKE '%" . $search . "%'
        OR `Price` LIKE '%" . $search . "%'";

仅FYI,BrandModelPrice是列,而不是行.

And just FYI, Brand, Model, and Price are columns, not rows.

这篇关于PHP在数据库中搜索多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆