gpt4 book ai didi

php - 带连接的 SQL 查询仅显示一个结果

转载 作者:行者123 更新时间:2023-11-29 08:00:34 25 4
gpt4 key购买 nike

我有一个 sql 查询,它应该显示表 swt_modules 中的所有记录,但它只显示第一行。

$query1 = mysql_query ("SELECT swt_modules.id, swt_modules.name, swt_exam_regs.name AS exam_regs
FROM `swt_modules`
JOIN `swt_exam_regs`
USING ( `id` )
WHERE swt_exam_regs.id = swt_modules.exam_regulation
ORDER BY swt_modules.name DESC , swt_modules.id DESC
LIMIT " . $limit . "");
while ($fetch1 = mysql_fetch_array ($query1))
{
...
}

我在这个表(swt_modules)中有3行,每行“exam_regulation”字段的值为1。在表swt_exam_regs中我只有1行2列 - id和name。 swt_modules.id 存储 id 号。我应该使用哪个联接才能查看所有记录?

result after join records in swt_modules table

最佳答案

我还建议使用 mysqli 或 pdo 而不是现已弃用的 mysql。

$query1 = mysql_query ("
SELECT
swt_modules.id,
swt_modules.name,
swt_exam_regs.name AS exam_regs
FROM swt_modules
LEFT JOIN swt_exam_regs on swt_exam_regs.id = swt_modules.exam_regulation
ORDER BY
swt_modules.name DESC,
swt_modules.id DESC
LIMIT $limit");

关于php - 带连接的 SQL 查询仅显示一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23938657/

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