我检查了数据以简单数组的形式进入$ posts_not_to_select中,其他一切都很好,但显示出以下错误:
异常#0(Zend_Db_Statement_Exception):SQLSTATE [42000]:语法 错误或访问冲突:1064您的SQL语法有错误; 检查与您的MySQL服务器版本相对应的手册 在'WHERE
entity_id
NOT IN附近使用正确的语法(选择post_id 在第1行的FROM mst_blog_store_post“不存储”的地方,查询是:SELECT *从mst_blog_post_entity
到created_at
的命令范围内,entity_id
不在1范围内(从mst_blog_store_post中选择post_id不在这里 store_id = 1)
$posts_not_to_selectssql1 = "SELECT post_id FROM mst_blog_store_post WHERE NOT store_id = $storeID";
$posts_not_to_select12 = $connection->fetchAll($posts_not_to_selectssql1);
$posts_not_to_select = array();
foreach ($posts_not_to_select12 as $key => $value){
$posts_not_to_select[$key] = $value['post_id'];
}
"SELECT * FROM `mst_blog_post_entity` ORDER BY `created_at` ASC LIMIT 1 WHERE `entity_id` NOT IN ( '" . implode( "', '" , $posts_not_to_select ) . "' )"
答案 0 :(得分:1)
SELECT * FROM `mst_blog_post_entity` WHERE `entity_id` NOT IN ( '" . implode( "', '" , $posts_not_to_select ) . "' )" ORDER BY `created_at` ASC LIMIT 1;
只需在phpmyadmin的SQL部分中运行此查询,一切就可以正常工作。
答案 1 :(得分:0)
ORDER BY
在WHERE
子句之后。
SELECT * FROM `mst_blog_post_entity`
WHERE `entity_id` NOT IN ( '" . implode( "', '" , $posts_not_to_select ) . "' )"
ORDER BY `created_at` ASC LIMIT 1
完整序列为: