查询:
SELECT * FROM ac_journal WHERE datetime < (SELECT datetime FROM ac_journal WHERE jid = 1089 AND rid IN ('2','3','4')) ORDER BY datetime DESC LIMIT 1
当我在phpmyadmin中执行此查询时,我得到了一行结果。
![enter image description here](https://istack.dev59.com/i3kgQ.webp)
function ac_journal_get_previous_entry($jid)
{
global $user; //1
echo $jid; //1089
echo "<br />'" . implode("','", array_keys($user->roles)) . "'"; //'2','3','4'
if ($jid > 0)
{
$result = db_query("SELECT * FROM {ac_journal} WHERE datetime < (SELECT datetime FROM {ac_journal} WHERE jid = ? AND rid IN (?)) ORDER BY datetime DESC LIMIT 1", array($jid, "'" . implode("','", array_keys($user->roles)) . "'"));
$obj = $result->fetchAll();
echo $result->rowCount(); //0
if (is_array($obj) && count($obj) > 0)
{
echo "HERE"; //never gets here
return "<a href='https://example.com/journal/" . $obj[0]->jid . "'>Previous</a>";
}
}
}
db_query()
的第二个参数 ->array($jid, "'" . implode("','", array_keys($user->roles)) . "'")
。 - Sean{ac_journal}
? - SeanWHERE jid = ? AND rid IN (?)
- 应该有某种类型的绑定发生吗?我错过了什么? - Funk Forty Ninerecho "SELECT * FROM {ac_journal} WHERE datetime < (SELECT datetime FROM {ac_journal} WHERE jid = ? AND rid IN (?)) ORDER BY datetime DESC LIMIT 1", array($jid, "'" . implode("','", array_keys($user->roles)) . "'")
- junkforce