Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is quite a complex question. Before trying to code your own variation from scratch, I suggest you take a look at the <a href="http://www.infinite-scroll.com/" rel="noreferrer">Infinite Scroll jQuery Plugin</a>. If that doesn't fix it, here's a possible solution:</p> <p><strong>Javascript</strong></p> <pre><code>$(document).ready(function () { loadData( 0 ); //Hide Loader for Infinite Scroll $('div.ajaxloader').hide(); }); function loadData ( last_id ) { var $entries = $('#entries'), $loader = $('.ajaxloader', $entries).show(); $.get( '/getentries.php', { last_id : last_id }, function( data ) { $entries.append( data ).append( $loader.hide() ); filterEntries(); }); }; //Isotope filter - no changes to this code so I didn't include it $(window).scroll(function () { if ($(window).scrollTop() &gt;= $(document).height() - $(window).height() - 10) { $('div.ajaxloader').show('slow'); loadData( $( '#entries item:last' ).data('id') ) } }); </code></pre> <p><strong>PHP</strong></p> <pre><code>&lt;?php //Connect to Database $con = new mysqli( 'localhost', 'root', 'root', 'awards' ); if( $con-&gt;connect_errno ) { die( 'Could not connect:' . $con-&gt;connect_error ); } $last_id = isset( $_GET['last_id'] ) ? (int)$_GET['last_id'] : 0; $stmt = $con-&gt;prepare( 'SELECT * FROM entry WHERE status = "registered" AND entry_id &gt; (?) ORDER BY entry_id LIMIT 0, 30' ); $stmt-&gt;bind_param( 'i', $last_id ); $stmt-&gt;execute(); $result = $stmt-&gt;get_result(); while( $row = $result-&gt;fetch_assoc() ) { //Get award cat ids $awardcat = $row['awards_subcategory_id']; print "&lt;div class='item item$awardcat clearfix' data-id='" . $row['entry_id'] . "'&gt;";//add award cat id to each div print '&lt;img class="image" src="http://localhost:8888/awardsite/wp-content/themes/award/placeholder.jpg" /&gt;'; print "&lt;p &gt; Studio: " . $row['studio'] . "&lt;/p&gt;"; print "&lt;p class='client'&gt; Client: " . $row['client'] . "&lt;/p&gt;"; print "&lt;p class='description'&gt; Description: " . $row['description'] . "&lt;/p&gt;"; print "&lt;p class='solutionprocess'&gt; Solution Process: " . $row['solution_process'] . "&lt;/p&gt;"; print "&lt;/div&gt;"; } $con-&gt;close(); </code></pre> <p>The Javascript code sends an AJAX GET request to the php script with the id of the last entry displayed in the list. The PHP script then returns 30 entries that come after that id. The original Javascript file had a bit of PHP code in it. I removed that, as I don't know what its purpose is (are you outputting the JS from a PHP script maybe?). Also, the whole <code>XMLHttpRequest</code> code can be shortened to the <code>$.get()</code> function. You're using jQuery anyway, so you don't need to reinvent the wheel. I used the <code>data-id</code> attribute to transmit the entry ids. That is a HTML5 specific attribute. If you don't want to use it, just use <code>id</code> instead, but remember that ids cannot start with a number - you should prefix it with a letter.</p> <p>In the PHP script, I used <code>mysqli</code> instead of the <code>mysql_*</code> functions. You should use <code>mysqli</code> or <code>PDO</code> from now on, as they are more reliable and secure than the (now deprecated) <code>mysql_*</code>. Your PHP installation most likely includes these extensions already. Note that I didn't handle database querying errors. You can write that code yourself. If you get other kinds of errors, post them here and I will try to fix them.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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