我想编写一个php查询,其中包括and和range条件。在屏幕快照中,您可以看到名为search的表的字段。同名的字段是范围。我想要选择查询,它应该包括所有的字段和它们的适当范围。
字段的名称是shape1、shape2(从shape1到shape2)等等,然后继续进行。
查询应该如下所示
select * from search where unique_id='$unique_id && (carat1='$carat1' between carat2='carat2') &&...还有其他字段,如cut和shape,都在一个查询中。我用json格式将值直接从android插入到数据库中。我的问题是我不知道合适的格式。
请帮帮我

发布于 2014-05-02 05:17:05
应该是这样的(一个例子)
select * from search
where unique_id= 10
and carat1 between 1 and 10
and shape1 between 1 and 10
and cut1 between 1 and 10编辑:
如果您试图从PHP运行SQL,那么格式将与下面的格式不同(如果列是像unique_id那样的整数类型,那么在替换值时不要放置'。对于字符串类型替换为' (如carat)
Select * from search
where unique_id = $unique_id
and carat between '$carat1' and '$carat2'
and color between '$color1' and '$color2'
and shape between '$shape1' and '$shape2'发布于 2014-05-02 05:12:06
mysql中中间的示例用法:
SELECT * FROM search
WHERE unique_id = 200 AND
carat BETWEEN 1 AND 5;请注意,中间和后面的值用来表示范围(1,5),而不是逻辑和运算符。
发布于 2014-05-02 05:29:29
试试这个,我希望这个能帮到你
SELECT * FROM search
WHERE unique_id = $unique_id AND
carat between $carat1 AND $carat2 AND
color like '%".$color1."%' AND
color like '%".$color2."%' AND
shape like '%".$shape1."%' AND
shape like '%".$shape2."%' https://stackoverflow.com/questions/23421056
复制相似问题