Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP/MySQL Show first X results, hide the rest
    primarykey
    data
    text
    <p>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.</p> <p>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. </p> <p>Many thanks in advance. S</p> <p><em>Thought I'd add the code I'm using below</em> </p> <pre><code>$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 =&gt; $newsItems) { echo '&lt;div class="date"&gt;' . $timePeriod . '&lt;/div&gt;' . PHP_EOL; echo '&lt;ul class="press"&gt;' . PHP_EOL; foreach ($newsItems as $item) { if ($bFirstTime) { echo '&lt;li&gt;'; echo '&lt;img src="'.$wwwUrl.'images/news/'.$item['image'].'" width="'.$item['imgWidth'].'" height="'.$item['imgHeight'].'" title="'.$item['title'].'" alt="'.$item['title'].'" /&gt; &lt;h3&gt;&lt;a href="'.$wwwUrl.'press-releases/'.$item["id"].'/'.$item["title"].'.php"&gt;'.$item["title"].'&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;'.substr($item['descrip'],0,244).'...&lt;/p&gt; &lt;p&gt;&lt;a href="'.$wwwUrl.'press-releases/'.$item["id"].'/'.$item["title"].'.php"&gt;Read more&lt;/a&gt;&lt;/p&gt; '; echo '&lt;/li&gt;' . PHP_EOL; $bFirstTime = false; } else { echo '&lt;li&gt;'; echo '&lt;a href="'.$wwwUrl.'press-releases/'.$item["id"].'/'.$item["title"].'.php"&gt;&lt;img src="'.$wwwUrl.'images/news/'.$item['image'].'" width="'.$item['tnWidth'].'" height="'.$item['tnHeight'].'" title="'.$item['title'].'" alt="'.$item['title'].'" /&gt;&lt;/a&gt; &lt;h3&gt;&lt;a href="'.$wwwUrl.'press-releases/'.$item["id"].'/'.$item["title"].'.php"&gt;'.$item["title"].'&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;'.substr($item['descrip'],0,100).'...&lt;/p&gt; &lt;p&gt;&lt;a href="'.$wwwUrl.'press-releases/'.$item["id"].'/'.$item["title"].'.php"&gt;Read more&lt;/a&gt;&lt;/p&gt; '; echo '&lt;div class="clear"&gt;&lt;/div&gt;' . PHP_EOL; echo '&lt;/li&gt;' . PHP_EOL; } } echo '&lt;/ul&gt;' . PHP_EOL; } echo '&lt;p&gt;&lt;a href="#" id="slick-toggle"&gt;Older posts...&lt;/a&gt;&lt;/p&gt;'. PHP_EOL; echo '&lt;div id="slickbox"&gt;This is the box that will be shown and display the rest of the news results. :)&lt;/div&gt;'. PHP_EOL; } else { echo 'We currently have no press releases available'; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload