How to change content without creating a new page?

Discussion in 'PHP' started by Clockwork Joe, Oct 29, 2013.

  1. #1
    When I create top 10 articles on my website (top 10 board games just for example,) I typically make one page with 10-6, and a next button at the bottom with a link to another page that has 5-1.

    I've been wanting to make it so it has more of a slideshow function. Like this website...

    http://whatculture.com/film/10-obscure-superheroes-that-badly-need-a-movie-treatment.php

    When you click "Next >>" it doesn't go to a whole new page, but quickly changes content and the website extension changes to ....php/2 ....php/3 and so on.

    What is this called? I would like to learn how to do this if anyone has any advice for me.
     
    Solved! View solution.
    Clockwork Joe, Oct 29, 2013 IP
  2. #2
    It's called AJAX, and is strictly not a PHP-question, but a javascript one. Simply put, you have a link which doesn't link to another page, or for that matter, has to be a link at all, which triggers a javascript function which polls content from a separate PHP-file (this file does all the processing), and then puts it into the page you're on. Pseudo-code follows:
    
    //mainpage
    <div id="contentgoeshere"></div>
    <button name="nextpage" id="nextpage">Go to next page</button>
    
    //js-function (yes, this is based on jQuery)
    $("#nextpage").click(function() {
    $.post('process.php', {var1, var2, var3}, function(data) { $("#contentgoeshere").html(data); } });
    });
    
    Code (markup):
    And in the process.php-file you'd have whatever you'd need to pull the content you wanted out.
    The variables in the js-function (var1, var2, var3) can be anything you want - you can use specific hidden input-field values, or just hardcode some counter into the js-function.

    All this is maybe a little abstract, but if you look up for instance "loading webpages via ajax" on google, you'll probably find a lot to read.[/code]
     
    PoPSiCLe, Oct 29, 2013 IP
  3. Clockwork Joe

    Clockwork Joe Greenhorn

    Messages:
    57
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #3
    Most excellent. Been wondering how to implement this for a while, now that I'm a bit less noobish in .js and php, I'm ready to bite into this.

    Thanks a ton.
     
    Clockwork Joe, Oct 29, 2013 IP
  4. digiface

    digiface Greenhorn

    Messages:
    44
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    23
    #4
    I would advice you to use dynamic scripting you should store the data in the table and change it as per your need using text editors facilities in the admin panel , this is the best way to solve your dynamic content problem.
     
    digiface, Oct 30, 2013 IP
    grandseo likes this.
  5. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #5
    I agree with digiface. The Ajax will be awesome for grabbing the new content from a folder or database..but to have those vars there I would connect it to a PHP dynamic page
    with a script that calls the data to be displayed (that way you're not making a new HTML page every time , instead you upload new data to be displayed to a folder /text file or database. The script should use AJAX engine to then trigger new event to load new data on each page (which will stop page refresh/reload.)
    The thing to consider though is that your pages won't index well with dynamic data. so if you're trying to SERP rank your Top 10 list.. its probably better to write it as separate articles and make it static. Top 10 lists are cliche' method for traffic and those pages can score high and you can of course use those pages to set links for others (of course by Google LAW you wouldn't CHARGE people money for those though..my god that would be horrible) :D
     
    ezprint2008, Oct 30, 2013 IP
  6. Clockwork Joe

    Clockwork Joe Greenhorn

    Messages:
    57
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #6
    I was just using a top 10 list as an example. I was finding it hard to explain what I was trying to do without knowing what it is called.

    Thanks to all of you for your input. I really appreciate it.
     
    Clockwork Joe, Oct 30, 2013 IP