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条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀