0

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

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

2 回答 2

0

您可以使用滚动分页之类的东西,当您滚动时会产生更多结果,就像 facebook/twitter 一样,请参见此处 jquery 滚动分页

另请参阅jquery 滚动分页 + php

于 2013-09-16T11:37:10.713 回答
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>
于 2013-09-16T11:19:52.873 回答