再次遇到问题,需要一些解决方法的帮助。
我需要限制每个具有任何结果的类别中检索结果的数量,以便仅显示4及以下类别将显示类别的链接,例如"查看更多结果"或类似的。
我最初的想法是,我需要更改或添加一些东西到它自己的实际查询,所以我添加了LIMIT 4,但结果是我最终只显示了一个类别,其中有4个项目类别就是这样。
请帮忙
这是我的脚本
if($category_type == 'links_only'){
$category_topic_query = 'SELECT l.category_name, l.category_folder, l.category_page, f.parentpageID, f.ImagePath, f.referring_url, f.templateTitle, f.xls, f.xlsx, f.ots, f.gdocs, f.numbers, f.templateImage, f.templimgwidth, f.templimgheight FROM lcategories l INNER JOIN Files f ON f.parentpageID = l.ID WHERE f.pageID = "0" ORDER BY f.parentpageID';
$resc = $db->prepare($category_topic_query);
$resc->execute();
$last_topic = NULL;
$add_rowNum = 1;
while ($category_topic = $resc -> fetch()){
$category_topic_ID = $category_topic['parentpageID'];
if($category_topic_ID !== $last_topic) {
$add_rowNum++;
$category_topic_name = str_replace("&", "&", $category_topic['category_name']);
$category_topic_url = DST.$category_topic['category_folder'].DS.$category_topic['category_page'];
$divider_div = ($add_rowNum % 2 == 0) ? '
<div class="clear"></div>' : FALSE ;
$first_ul = ($category_topic_ID == 1) ? FALSE : '</ul>
</div>'.$divider_div ;
print<<<END
$first_ul
<div style="float: left; margin: 10px; width: 349px;">
<h2 class="h_unln"><a href="$category_topic_url">$category_topic_name</a></h2>
<ul class="arrow">
END;
$last_topic = $category_topic_ID;
}
$links_array = ($category_topic['referring_url'] == NULL) ? FALSE :'
<li>
<ul>
<li><a href="'.DST.$category_topic['ImagePath'].DS.$category_topic['referring_url'].'"><img src="'.$image_path.$category_topic['ImagePath'].DS.$category_topic['templateImage'].'" width="'.$category_topic['templimgwidth'].'" height="'.$category_topic['templimgheight'].'" title="'.$category_topic['templateTitle'].'"></a></li>
<li><a href="'.DST.$category_topic['ImagePath'].DS.$category_topic['referring_url'].'">'.$category_topic['templateTitle'].'</a></li>
<li>'.$numbers_im.$gdocs_im.$ots_im.$xlsx_im.$xls_im.'</li></ul></li>';
print<<<END
$links_array
END;
}
print<<<END
</ul>
</div>
<div class="clear"></div>
END;
}
答案 0 :(得分:0)
$limit = ($_GET['limit'])? $_GET['limit'] : 4 ; //For the first query only 4 links will be displayed
$offset = ($_GET['offset'])? $_GET['offset'] : 0;
像这样调整您的查询:
$category_topic_query = "SELECT l.category_name, l.category_folder, l.category_page, f.parentpageID, f.ImagePath, f.referring_url, f.templateTitle, f.xls, f.xlsx, f.ots, f.gdocs, f.numbers, f.templateImage, f.templimgwidth, f.templimgheight FROM lcategories l INNER JOIN Files f ON f.parentpageID = l.ID WHERE f.pageID = '0' ORDER BY f.parentpageID
LIMIT $limit OFFSET $offset";
然后在“看到更多链接”
<a href='<? echo $_SERVER['PHP_SELF'] ?>?limit=20&offset=4'> See more </a>
答案 1 :(得分:0)
你可以使用像滚动分页这样的东西,当你像facebook / twitter一样滚动时会产生更多的结果 看这里 jquery scroll pagination