道歉没有正确写出标题。我正在寻找一个随机的mysql id,其类型值设置为Electro
SELECT * FROM rtsubmissions ORDER BY rand() WHERE `$genretypefix` DESC LIMIT 0, 1
Fred在WHERE之后解决了第一部分ORDER BY ..但仍然无法使变量工作
编辑:
$sorttype = $_GET['sort'];
$genretype = $_GET['gn'];
$genretypefix = "genre='" . $genretype . "'";
if ($sorttype == 'new') {
$sql = "
SELECT * FROM rtsubmissions ORDER BY id DESC LIMIT 0, 1
";
} elseif ($sorttype == 'genre') {
$sql = "
SELECT * FROM rtsubmissions WHERE `$genretypefix` ORDER BY rand() DESC LIMIT 0, 1
";
} else {
$sql = "
SELECT * FROM rtsubmissions ORDER BY played DESC LIMIT 0, 1
"; }
EDIT2:根据评论删除`并且它有效,谢谢你
答案 0 :(得分:0)
试试这个:
"SELECT * FROM rtsubmissions WHERE $genretypefix ORDER BY rand() DESC LIMIT 0, 1"