Giter Club home page Giter Club logo

php-infinite-scrolling's Introduction

Infinite scrolling using PHP, jQuery and a bit of AJAX

By combining PHP and jQuery's functionality we can create amazing web applications.

Infinite scrolling is a functionality that is already well known to the many web surfers. This functionality is very common nowadays on many popular social media websites (such as Twitter and Facebook).

Tournas Dimitiros in late 2012 wrote an article describing how to Create an Infinite Scroll Page Using Ajax-PHP and JQuery.

Requirements

  • PHP 5+
  • MySQL 5+

Only basic PHP and MySQL knowledge is required to set up this functionality. Customizing the code to your own needs isn't very difficult if you have intermediate PHP knowledge.

The the article link above for more information on how these scripts work.

Overview

  1. javascript/custom_jquery.js: This file contains all the client-side code (requires jQuery). The database will be queried via an AJAX-call.
  2. jquery-masterLoader.php: This file makes the first connection to the database to return the first 30 rows from the MySQL query.
  3. jquery-loadMoreComments.php: This file will respond to AJAX requests.
  4. world_country.sql : Contains the data that you can use to emulate this functionality, just uplad this file into your database via phpMyAdmin or via the command line.

Database credentials are stored into an separate file (conf/my.ini) . These credentials are parsed with PHP. Although direct access to the directory of this file is denied via .htaccess, it is good practice is to upload this file into a non publicly accessible directory of your server.

The jQuery library is directly downloaded from Google's CDN, you may wish to change this later.

require_once is used to embed the two PHP files into the index file. Direct access is detected and prohibited.

Both PHP scripts have error reporting disabled. For development, just comment the lines out on these scripts.

The database connection is made via the mysqli adapter (supported on most modern hosting environments). A custom Exception handler will be used for custom error messages, so critical detailes will not be displayed into visitor's browser if a database error might occur.

Changelog

13/06/2013: Updates committed

  • Rewrote the README file.
  • Replaced debug version of js file with a debug switch.

02/09/2012: New version released (V0.4)

  • An extra line of code is added on javascript/custom_jquery.js (line 33). It just disables the Ajax-call when no more results are returned from the PHP-script (most likely because the database has no more results to deliver) . This prevents Ajax from sending requests to the server after it receives an empty result.
  • A second file is added into the javascript folder (custom_jquery_debug.js) . This file has extensive "console.log" lines enabled, various messages are displayed into browser's console panel (of course browser's developer tool should be enabled first). If there is need for client-side debugging, import this file into index.php instead of the defauld file (custom_jquery.js).

php-infinite-scrolling's People

Contributors

timgws avatar tournasdim avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.