繁体   English   中英

与显示“查看更多结果”相比,每个类别的提取结果数限制为仅4

[英]limit number of fetched results per category to only 4 than display “See More Results”

再次遇到问题,需要一些帮助来解决。

我需要限制每个类别中根本没有任何结果的每个类别中检索到的结果的数量,以仅显示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;
}
    $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>

当滚动只是像Facebook / Twitter的看到这里,您可以使用类似滚动分页,这将产生更多的结果jQuery的滚动分页

另请参阅jQuery滚动分页+ PHP

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM