Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't increment your PHP variables after the page has loaded. You are trying to increment them client-side with JavaScript. You are going to need to call that PHP using AJAX if you want to do this without refreshing the page, and even then you'll want to increment a javascript variable to keep track of where you are.</p> <p>EDIT: I went a little nuts creating an ajax routine using PHP and JavaScript, specifically the jQuery library, which you will need to link to for this to work. You may also need to modify parts of the script to work with what you're trying to accomplish, but this certainly is a guide for running your ajax app as you're hoping to. </p> <p>Start by making a PHP file with this script:</p> <pre><code>&lt;?php // Set content header to json header('Content-Type: application/json'); // Get the index from the AJAX $index = $_GET['index']; // Grab file contents &amp; parse $html = file_get_contents("http://www.9gag.com"); preg_match_all( '|http://d24w6bsrhbeh9d\.cloudfront\.net/photo/.+?\.jpg|', $html, $gags); // Send filename back to AJAX script as JSON echo json_encode(array($gags[0][$index])); ?&gt; </code></pre> <p>Then, in your HTML, include this jQuery to complete AJAX calls to your PHP script, and update the DOM with the data from the PHP script. </p> <pre><code>&lt;script&gt; $(function() { 'use strict'; // Initiate index variable var index = 0; // Load initial image loadImage(index); // Add click event to a button with class of next-btn $('.next-btn').click(function(e) { e.preventDefault(); // Increment index to get next image index++; // Run AJAX function to retrieve image loadImage(index); }); // Add click event to a button with class prev-btn $('.prev-btn').click(function(e) { e.preventDefault(); // Decrement the index if it isn't 0 if (index &gt; 0) { index--; } // Run AJAX function to retrieve image loadImage(index); }); }); function loadImage(index) { 'use strict'; $.ajax({ type: 'GET', url: 'your-php-script.php', // Filepath to your PHP script data: 'index='+index, // Index is passed through GET request dataType: 'json', // Return JSON success: function (data) { // If the php script succeeds // Change img with class of pic's src // to the filename retrieved from php $('.pic').attr('src', data[0]); } }); } &lt;/script&gt; </code></pre> <p>Configuring this for your needs will require some serious PHP and jQuery/JavaScript knowledge, as some debugging will likely be needed. Good luck!</p> <p>EDIT 2: I uploaded the working (tested, it works) source files to my website if you want to download. Please accept answer and let me know you grabbed the files... </p> <p><a href="http://www.wedgewebdesign.com/files/ajax-image-loader.zip" rel="nofollow">http://www.wedgewebdesign.com/files/ajax-image-loader.zip</a></p>
    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.
    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