In this post we explain how to create advanced pagination in PHP and MySql with jQuery in codeigniter. It is a MVC structure framework, so we explain each and every thing as per structure.
Step 1: We take an example to describe you in detail. Suppose on view page you will showing 3 property listing and below Load More button to show more listing on button click.
So whenever you click that button property list increase by 3. Means first time you click load more button 6 property show than after 9 and more on.
You are using foreach loop to show first 3 property on view page. Declare one $count variable outside the for loop and initialize its value by 1. Assign this count variable to another $newproperty variable. After one loop execute increment $count variable to 1. This $count variable store your last showing property id on page. See below code example.
Now check if your property list count is greater than $newproperty value, than display load more button. This condition because to check that you have more than 3 property to show on page.
Step 2: Check below load more button functionality.
Declare $newproperty, $proerty_name, $count and $property_rowcount as hidden input value.
Step 3: Now define the ajax functionality for load more on same view page. This ajax function called on the basis of “show_more” id of load more listing text.
In this script we can get last property showing id by #tutidval and count variable by #prevval and property name by #cntryname.
You May Also Like:
How to Install Magento Security Patch via Putty
Code to Use Paypal Payment Gateway on Website
How to Authenticate with D&B Direct API Web Service
How to Add New Product in Bigcommerce via API V2
How to Connect With Cloudshare Rest API
How to Use Google API to Get Google Analytics Data with PHP
Note: We use property name for search the property list from the database.
Step 4: Now we define “loadmoredata” function in site controller.
Step 4: Now define “loadmore_listing” Model function to get next 3 property list from database. Also get total property count entry in database table using another “search_querypackage_count” function in model.
Step 5: Now create an another “loadmorelist” page in View section to show load more property content.
Through follow above complete process you can easily implement Load More functionality on your codeigniter website. make sure use right code on correct web page. This is the Advanced Pagination in PHP in Mysql.
Note: Above define variable change as per your website and database table structure. So change it as per your need.