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");
似乎无法找到我在这里失踪的东西......我想在"之间找到"将语句转换为php变量,以便它将使用给定的输入更改查询项。不同范围有多种不同的输入。当我手动进入之间时(例如SELECT * FROM表WHERE col BETWEEN 1000 AND 2000 order by datetime desc LIMIT 50)我没有问题。它不适用于变量 这是我在这里的第一篇文章,所以非常感谢任何帮助!
答案 0 :(得分:0)
试试这个:
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");
答案 1 :(得分:0)
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变量。任何问题都没有问题让我知道!