Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7180453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:21:04+00:00 2026-05-28T17:21:04+00:00

I’m creating an events website using PHP. I have a database with an events

  • 0

I’m creating an events website using PHP. I have a database with an “events” table that includes id, title and date (Y-m-d).

My index page displays the first 30 events, in date order, starting with today. When you click “More”, 30 more events are displayed via AJAX. AJAX loads more.php within index.php, and index.php passes the latest id/date to more.php via a PHP session.

I want to be able to display “More” again and again, so that each time the user clicks it, 30 more events are displayed beneath the previous events (like what happens when you scroll all the way down on Twitter).

Unfortunately, my “More” button works the first time (when clicked from index.php), but when clicked on in more.php, quickly loops again and again through the id/date variables until there aren’t any more events left.

How do I create my desired More button via AJAX?

Here’s relevant code from index.php:

<!-- "More" button JavaScript. Loads 10 more events when clicked -->
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript">
  $(document).ready(function(){
    $("more").click(function(){
      $("more").load('more.php');
    });
  });
</script>

<?php
  session_start();
  $today = date('Y-m-d');
  $result = mysql_query("SELECT * FROM events WHERE date>='$today' ORDER BY date LIMIT 0, 30");
  while($row = mysql_fetch_array($result))
    {
    echo $row['id'];
    echo $row['title'];
    echo $row['date'];
    echo "<br />";
    // Grabs date/id of last event echoed
$nId = $row['id'];
$nDate = $row['date'];
    }
  // Sends last date/id echoed to more.php
  $_SESSION['nDate']=$nDate;
  $_SESSION['nId']=$nId;    
?>
<!-- This more tag seems to work with my JavaScript -->
<more>More</more>

And more.php:

<!-- "More" button JavaScript. Loads 30 more events when clicked -->
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript">
  $(document).ready(function(){
    $("more").click(function(){
      $("more").load('more.php');
    });
  });
</script>

<?php
  session_start();
  $nId = $_SESSION['nId'];
  $nDate = $_SESSION['nDate'];
  $result = mysql_query("SELECT * FROM events WHERE date>='$nDate' && id>='$nId' ORDER BY date LIMIT 1, 30");
  while($row = mysql_fetch_array($result))
    {
    echo $row['id'];
    echo $row['title'];
    echo $row['date'];
    echo "<br />";
    $nId = $row['id'];
    $nDate = $row['date'];
    }   
  $_SESSION['nDate']=$nDate;
  $_SESSION['nId']=$nId;    
?>
<more>More</more>

Thanks a lot in advance, guys 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:21:05+00:00Added an answer on May 28, 2026 at 5:21 pm

    You have extra unneeded data here. Try this example.

    index.php:

    <?php  
    // THAT SHOULD BE BEFORE ANY OUTPUT IS SENT TO THE BROWSER
        session_start();  
    ?>
    <!-- "More" button JavaScript. Loads 10 more events when clicked -->
    <script type="text/javascript" src="ajax.js"></script>
    <script type="text/javascript">
      $(document).ready(function(){
        $("more").click(function(){
          $('<div style="display:none;"/>').insertBefore($(this))
                  .load('more.php', function(){$(this).slideDown();});
        });
      });
    </script>
    
    <?php
    include('more.php');  
    ?>
    <!-- This more tag seems to work with my JavaScript -->
    <more>More</more>
    

    And more.php:

    <?php
      // include here some code for connection to DB
      if (!isset($_SESSION)) 
      {
          session_start();
          $nId = $_SESSION['nId'];
          $nDate = $_SESSION['nDate'];
          $result = mysql_query("SELECT * FROM events WHERE date>='$nDate' && 
                                id>='$nId' ORDER BY date LIMIT 1, 30");      
      }
      else
      {
          $today = date('Y-m-d');
          $result = mysql_query("SELECT * FROM events WHERE date>='$today' 
                             ORDER BY date LIMIT 0, 30");
      }
    
      while($row = mysql_fetch_array($result))
        {
        echo $row['id'];
        echo $row['title'];
        echo $row['date'];
        echo "<br />";
        $nId = $row['id'];
        $nDate = $row['date'];
        }   
      $_SESSION['nDate']=$nDate;
      $_SESSION['nId']=$nId;    
    ?>
    

    And, probably, you should add the way to stop this expansion when there are no more records in db.

    ps: and why do you need nonstandard tag more? use, for example, <div id='more'>More</div>. Then your $("more") will change to $("#more").

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.