gpt4 book ai didi

php - sql查询不适用于order by

转载 作者:可可西里 更新时间:2023-11-01 08:06:00 25 4
gpt4 key购买 nike

这是我原来有效的查询

 Select * FROM story st, sentences s, speaker sp 
WHERE (st.lesson_id = '1' AND
st.speaker_id = sp.speaker_id AND
st.sentence_id = s.sentence_id)

当我尝试添加一个 Order By 时它崩溃了。

 Select * FROM story st, sentences s, speaker sp 
WHERE (st.lesson_id = '1' AND
st.speaker_id = sp.speaker_id AND
st.sentence_id = s.sentence_id) ORDER BY st.story_in_lesson_id ASC

不知道为什么会坏。

编辑:这是我得到的错误 Fatal error: Call to a member function fetch_object()

编辑:我的 PHP 代码

$result = $mysqli->query("Select * FROM story st, sentences s, speaker sp 
WHERE st.lesson_id = '1' AND
st.speaker_id = sp.speaker_id AND
st.sentence_id = s.sentence_id
ORDER BY st.story_in_lesson_id ASC");

while ($value = $result->fetch_object()) {
//never goes in here fails at the fetch_object()
}

编辑:

有没有可能因为我正在尝试查询多个表而不起作用?只有一个表具有故事表 story_in_lesson_id。当我仅在该表上运行查询时,它可以找到。

编辑:

更多信息,将数据库复制到我的工作 Mac 上,查询有效!!!但是为什么它在我的电脑上不起作用??顺便说一句,我现在通过在 Sequel Pro 中运行它来严格测试查询。

最佳答案

亲爱的,请删除你的 where 条件......可能它正在工作,请给我回复你得到的结果。

SELECT * 
FROM story st
INNER JOIN sentences s
ON st.sentence_id = s.sentence_id
INNER JOIN speaker sp
ON st.speaker_id = sp.speaker_id
ORDER BY st.story_in_lesson_id ASC

关于php - sql查询不适用于order by,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20603631/

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