Infinite scrolling , certainly this functionality is already well known to the majority of web-surfers . This functionality is common nowadays on the most-visited social-media websites ( Twitter , Facebook ) . The article of this code is located at >>>>>>> .
Actually there are no special requirements to set-up these code snippets . A web server that supports PHP 5+ and Mysql 5+ is adequate .
Only basic PHP and Mysql knowledge is required to set up this functionality on your development computer . Customizing the code to your own needs isn't very difficult if you have intermediate PHP knowledge . Of course you can visit the afforementioned link to request for help .
Note : I 'll not respond to messages like "I have installed the scripts , but it doesn't work . Please help me " .Your request should be structured on technical details . If you have basic PHP knowledge and exhausted your skills then you are welcome to request for help .
- To avoid "spaggeti code " the code is separated into three files
:
1) javascript/custom_jquery.js : this file contains all the client-side code (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 Mysql query results .
3) jquery-loadMoreComments.php : It respond to AJAX requests .
- 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 , a 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 AJAX API
, so your server is saved from a bit of resource-cycles .
- Requere_once is used to embed the two PHP files into the index file . Direct access is detected and prohibited .
- 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 command line .
- Both PHP scripts have error reporting disabled . For development
, just comment the proper lines on these scripts .
- Database connection is made via the Mysqli adapter
(supported on all hosting environments) . A
custom Exception handler will thrown custom error messages
, so critical detailes will not be displayed into visitor's browser if
a database error might occure .
- 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 even if it receives empty results .
- 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) .
/**
* Infinite scrolling
*
* http://tournasdimitrios1.wordpress.com
*
* @copyright Tournas Dimitiros 2012
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @author Tournas Dimitrios <[email protected]>
* @version 0.3
*
*/