gpt4 book ai didi

php sql语法,获取带有id变量的随机行/包含行

转载 作者:行者123 更新时间:2023-11-29 03:33:37 24 4
gpt4 key购买 nike

抱歉标题措辞不当。我正在寻找一个类型值设置为 Electro 的随机 mysql id

SELECT * FROM rtsubmissions ORDER BY rand() WHERE `$genretypefix` DESC LIMIT 0, 1

Fred 解决了第一部分,ORDER BY after WHERE.. 仍然无法让变量工作

编辑:

$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:根据评论删除了 ` 并且有效,谢谢

最佳答案

试试这个:

"SELECT * FROM rtsubmissions WHERE $genretypefix ORDER BY rand() DESC LIMIT 0, 1"

关于php sql语法,获取带有id变量的随机行/包含行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26857364/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com