如何使用多个条件从数据库中查找值?

时间:2013-05-22 03:54:17

标签: mysql

我想根据其他三个字段中的信息从单个字段中检索数据。 举个例子,如果我有一个包含以下字段的表: 宽度,长度,高度,重量和颜色。 我想得到字段颜色的值,其中width = $ value和length = $ value2和height = $ value。

4 个答案:

答案 0 :(得分:0)

select color from table_name where width = $value and length = $value2 and height = $value3

我认为你的意思是使用SQL ....

答案 1 :(得分:0)

SQL几乎就是你在问题中所写的内容了!

select color from yourtable
     where width = $value and length = $value2 and height = $value

PHP:

$result = $mysqli->query("SELECT color FROM yourtable WHERE width = $value AND length = $value2 AND height = $value");

答案 2 :(得分:0)

select 'singleFieldName' from table where width = $value AND length = $value2 AND height = $value3

答案 3 :(得分:0)

试试这个

    echo $query = "select color from yourtable_name
        where width = '".$value1."' and length = '".$value2."' and height = '".$value3."'";