作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何在 PHP/PostgreSQL 中创建 50 个 pg_execute
命令的情况下将数组放入下面的 WHERE 子句?
// to get the question_ids of the newest questions
$result_q_id = pg_prepare($dbconn, "query6", "SELECT question_id
FROM questions
ORDER BY was_sent_at_time
DESC LIMIT 50;"
);
$result_question_id = pg_execute($dbconn, "query6", array());
// to get all question ids
$question_ids = pg_fetch_all($result_question_id);
// to get titles, question_id from the db by using the question ids
$result = pg_prepare($dbconn, "query8", "SELECT title
FROM questions
WHERE question_id = $1 // Problem here! How to get many WHERE's?
ORDER BY was_sent_at_time
DESC LIMIT 50;"
);
$result = pg_execute($dbconn, "query8", array($question_ids));
// Problem here, since it is an array
我第一次收到文本 Problem here
的行出现以下错误。
Warning: pg_execute() [function.pg-execute]: Query failed: ERROR: invalid input syntax for integer: "Array" in /var/www/codes/handlers/handle_questions_by_time.php on line 22
Call Stack
最佳答案
子查询解决了这一切......
$result = pg_prepare($dbconn, "query8",
"SELECT title
FROM questions
WHERE question_id in (SELECT question_id
FROM questions
ORDER BY was_sent_at_time
DESC LIMIT 50)
ORDER BY was_sent_at_time
DESC LIMIT 50;"
关于php - 将数组放入 PHP 中的 WHERE 子句而不命中 X 次 Postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1280251/
我是一名优秀的程序员,十分优秀!