DataTables Example – Server-side Processing with PHP

In previous post Data Table jQuery Plugin, we have learn what is jQuery datatable plugin and how to use jQuery datatable in your application,now in this tutorial i will describe how to use data table with server side scripting.I am using PHP and MySQL to get records from server side.In this tutorial our aim to get data from MySQL with help of php and passed data to jQuery datatable constructor.

Also Checkout other tutorial of Datatable,

datatable-with-php

There are following steps need to achieve over goal:

Step 1: we will include jquery datatable and jquery library.

Step 2: Created HTML table in your web page.

Step 3: Apply Datatable functionality on our HTML table.

Step 4: Now we will create response.php file and write down below code.

Here we have taken constant array instead of MySQL records, I am assuming you will replace this constant array with your MySQL result set.

26 thoughts on “DataTables Example – Server-side Processing with PHP

  1. Nice Tutorial Parvez. I found it very simple than datatable website. I’m working on bootstrap 3 with datatables with huge dataset coming from DB, I just wanted it to be from server rather than sending the whole dataset to datatables and leave this to it. But having huge dataset (>10K records) taking little time. Can you please provide the code to get the data from server with pagination, sorting and search. Thanks a ton in advance..

      • Hi,
        In step 4 i have mensioned static array,

        $data = array(
        array(‘Name’=>’parvez’, ‘Empid’=>11, ‘Salary’=>101),
        array(‘Name’=>’alam’, ‘Empid’=>1, ‘Salary’=>102),
        array(‘Name’=>’phpflow’, ‘Empid’=>21, ‘Salary’=>103) );

        below i am providing roughly idea:
        $sql =”select * from studens”;

        $data = mysql_fetch_assoc($sql),

        now you can get associative array form your database.

  2. Hello Parvez, I am Satya a beginner in Datatables, I am working in such a situation that I need to generate datatable on button click and it should get the data from the database using Joins, I tired doind few cases but I get Invalid json format, so can you suggest me how to do that please ?

  3. Hi! Thanks a lot, this is really helpfull for my project. I am a Computer Engineering student, still learning about this kind of things and I bookmarked this website for reference. Once again thanks a lot!!

  4. Hi Parvez,

    Love your script much, i has same question with Rahul. There is almost 10K dataset in my database and took so long to load into dataset. I’m waiting your next tutorial based on this case.

    Cheers

  5. Hi,

    I have used this method, it is working fine, but i have few questions:
    1- If i need to add static values to the last column, example: Delete icon, to delete the record
    2- Color the line based on a certain value
    3- Instead of Previous, Next to use <>
    4- Pass a certain value to filter the select in the server side
    5- Align the pagination with the Showing number of entries

    Thank you

    • The point 2,3 and 5 can be handle by css and rest of them can be found in datatable dos easily,if you not find let us know,i ll share link or tutorial for them.

  6. Hi, this is a good example thank you a lot,
    could you please give me and example with the Mysql records
    Regards

  7. Hi this is good example of static value can you please give me example of Mysql record i had error
    json data from server cannot be parse…

    • yes, datatable providing many pagination nav options, You can get more information from datatable official website.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.