dsgdg46465 2010-09-29 11:00
浏览 383
已采纳

PHP / MySQL显示第一个X结果,隐藏其余部分

Does anyone know how to bring in all of a mysql tables' results, only show the first X, (say 10), and then hide the rest using jquery? Basically, as I've already got the jquery, I just need to know how to show only the first X results in one div, then the rest in a seperate div.

My aim is to only show the first 10 results, but provide a link at the bottom of the page allowing the user to show all of the results. Was thinking the hyperlink could just re-execute the query but thought it would be easier to show/hide using jquery.

Many thanks in advance. S

Thought I'd add the code I'm using below

$query = "SELECT * FROM ispress WHERE active = '1' ORDER BY YEAR(date) DESC, MONTH(date) DESC LIMIT 0, 7";
                        $resultSet = mysql_query($query);

                        if (mysql_num_rows($resultSet))
                        {
                          $newsArray = array();
                          while ($newsResult = mysql_fetch_array($resultSet))
                          {                                   
                        $newDate =  $newsResult['date'] ;    
                        $timePeriod = date('F  Y ',strtotime($newDate));    
                        $bFirstTime = true;

                        if (!isset($newsArray[$timePeriod]))
                        {
                          $newsArray[$timePeriod] = array();
                        }
                        $newsArray[$timePeriod][] = $newsResult;                            
                          }
                          foreach ($newsArray as $timePeriod => $newsItems)
                          {                                                                                    
                        echo '<div class="date">' . $timePeriod . '</div>' . PHP_EOL;          
                           echo '<ul class="press">' . PHP_EOL;
                        foreach ($newsItems as $item)
                        {                    
                        if ($bFirstTime) {
                        echo '<li>';
                         echo '<img src="'.$wwwUrl.'images/news/'.$item['image'].'" width="'.$item['imgWidth'].'" height="'.$item['imgHeight'].'" title="'.$item['title'].'" alt="'.$item['title'].'" />
                                <h3><a href="'.$wwwUrl.'press-releases/'.$item["id"].'/'.$item["title"].'.php">'.$item["title"].'</a></h3>                                    
                                <p>'.substr($item['descrip'],0,244).'...</p>
                                <p><a href="'.$wwwUrl.'press-releases/'.$item["id"].'/'.$item["title"].'.php">Read more</a></p>    
                                ';
                         echo '</li>' . PHP_EOL;    
                        $bFirstTime = false;
                        } else {
                           echo '<li>';
                         echo '<a href="'.$wwwUrl.'press-releases/'.$item["id"].'/'.$item["title"].'.php"><img src="'.$wwwUrl.'images/news/'.$item['image'].'" width="'.$item['tnWidth'].'" height="'.$item['tnHeight'].'" title="'.$item['title'].'" alt="'.$item['title'].'" /></a>
                                <h3><a href="'.$wwwUrl.'press-releases/'.$item["id"].'/'.$item["title"].'.php">'.$item["title"].'</a></h3>                                    
                                <p>'.substr($item['descrip'],0,100).'...</p>
                                <p><a href="'.$wwwUrl.'press-releases/'.$item["id"].'/'.$item["title"].'.php">Read more</a></p>    
                                ';
                        echo '<div class="clear"></div>' . PHP_EOL;
                         echo '</li>' . PHP_EOL;                            
                            }                                                        
                           }
                        echo '</ul>' . PHP_EOL;                            
                              }
                            echo '<p><a href="#" id="slick-toggle">Older posts...</a></p>'. PHP_EOL;
                            echo '<div id="slickbox">This is the box that will be shown and display the rest of the news results. :)</div>'. PHP_EOL;
                        }                                                
                        else
                            {
                          echo 'We currently have no press releases available';
                        }
  • 写回答

6条回答 默认 最新

  • duangan2307 2010-09-29 11:12
    关注

    This will hide the first 10 children. How are you planning on showing the other results? Buttons, fields, jqueryui widgets? You will just need to add a click event which calls this function.

    function limit_results(start, end) {
        $('#things > .thing').each(index) {
            if(index < end && index >= start) {
                $(this).hide();
            }  
        }
    }
    limit_results(1,10);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)