我有以下问题:这是我的表的结构
这是我的代码:
$SQL_NEXT_PROJECT_ID ="SELECT id FROM projects WHERE id < '".$id_project."' and project_types_id='".$project_type_id."' ORDER BY id DESC LIMIT 1";
$conn->query($SQL_NEXT_PROJECT_ID);
foreach ($conn->query($SQL_NEXT_PROJECT_ID) as $rowProjectNext) {
$next_project_id = $rowProjectNext['id'];
}
$SQL_PREVIOUS_PROJECT_ID ="SELECT id FROM projects WHERE id > '".$id_project."' and project_types_id='".$project_type_id."' ORDER BY id ASC LIMIT 1";
$conn->query($SQL_PREVIOUS_PROJECT_ID);
foreach ($conn->query($SQL_PREVIOUS_PROJECT_ID) as $rowProjectPrevious) {
$previous_project_id = $rowProjectPrevious['id'];
}
问题是我需要使用“图像”表中的附加条件进行查询,我必须评估主字段 = '1',我一直在尝试使用内部连接但它似乎不起作用,在这里我附上我一直在尝试的查询
$SQL_NEXT_PROJECT_ID ="SELECT projects.id FROM projects INNER JOIN images WHERE projects.id > '".$id_project."' and project_types_id='1' and main='1' ORDER BY projects.id DESC LIMIT 1";
基本上我需要做的是根据项目的当前 id ($id_project) 创建下一个/上一个指向特定类型项目 (project_types_id) 的链接,同时考虑到项目应该有一个具有主字段的图像这一事实等于“1”
希望我能很好地解释自己...