if($band == "something"){
$que = "BETWEEN '1000' and '2000'";
}
if($band == "somethingelse"){
$que = "BETWEEN '2000' and '5000'";
}
if($band == "somethingelseelse"){
$que = "BETWEEN '5000' and '10000'";
}
if($band == "againsomethingelse"){
$que = "BETWEEN '10000' and '30000'";
}
$query = mysql_query("SELECT * FROM table WHERE col $que order by datetime desc LIMIT 50");
似乎找不到我在这里错过了什么…我想把"between"语句变成一个php变量,这样它就会用给定的输入改变查询项。对于不同的范围有多个不同的输入。当我手动输入between时,例如(SELECT * FROM table WHERE col between 1000 AND 2000 order by datetime desc LIMIT 50),我没有问题。它对变量不起作用这是我在这里的第一个帖子,所以任何帮助都非常感谢!
试试这个:
if($band == "something"){
$que = "BETWEEN '1000' AND '2000'";
}else{
$que = "BETWEEN '2000' AND '5000'";
}
$query = mysql_query("SELECT * FROM table WHERE col $que ORDER BY datetime DESC LIMIT 50");
if($_GET["band"] == "something"){
$quelow = 1000;
$quehigh = 2000;
}
if($_GET["band"] == "somethingelse"){
$quelow = 2000;
$quehigh = 5000;
}
if($_GET["band"] == "somethingelseelse"){
$quelow = 5000;
$quehigh = 10000;
}
if($_GET["band"] == "againsomethingelse"){
$quelow = 10000;
$quehigh = 20000;
}
$query = mysql_query("SELECT * FROM table WHERE col BETWEEN $quelow AND $quehigh order by datetime desc LIMIT 50");
我自己解决了这个问题,我从我的网页上得到了不正确的php变量。工作没有问题,任何问题让我知道!