We help IT Professionals succeed at work.
Get Started

How to do server-side processing

Jazzy 1012
Jazzy 1012 asked
Last Modified: 2017-11-29
I have this datatable:
<table class="table table-striped" id="sales-order-table">
			<th> ID</th>
			<th> Last Name</th>
			<th>Option ID</th>
			<th>Meal Name</th>
	while($row_to_get_meal = mysqli_fetch_assoc($result_to_get_meal)){

	$order_id = $row_to_get_meal['order_id'];
	$query_to_get_info = "select orders.id, first_name,last_name, orders.user_id, email, charge_date, orders.status from orders left join users on orders.user_id = users.id where orders.id = '$order_id'";
	$result_to_get_info = mysqli_query($conn,$query_to_get_info);
	if(mysqli_num_rows($result_to_get_info) == 0)
	$row_to_get_info = mysqli_fetch_assoc($result_to_get_info);
		<td><?php echo $row_to_get_info['user']; ?></td>
	    <td><?php echo $row_to_get_info['first_name']; ?></td>
	    <td><?php echo $row_to_get_info['last_name']; ?></td>
	    <td><?php echo $row_to_get_info['email']; ?></td>
	    <td><?php echo $row_to_get_info['id']; ?></td>
		<td><?php echo $row_to_get_info['date']; ?></td>
		<td><?php echo $row_to_get_info['status'];?></td>
		<td><?php echo $row_to_get_meal['meal_option_id'];?></td>
		<td><?php echo $row_to_get_meal['display_name'];?></td>
		<td><?php echo $row_to_get_meal['amount'];?></td>
		<td><?php echo $row_to_get_meal['count'];?></td>

		<?php }
        "pageLength": 50,
        dom: 'Bfrtip',
        buttons: [
                	  extend: 'csv', text: 'Download CSV' }

Open in new window

It contains over a thousand columns, how can I make it server-processing?
I know that I have to use this:
$(document).ready(function() {
    $('#example').DataTable( {
        serverSide: true,
        ordering: false,
        searching: false,
        ajax: function ( data, callback, settings ) {
            var out = [];
            for ( var i=data.start, ien=data.start+data.length ; i<ien ; i++ ) {
                out.push( [ i+'-1', i+'-2', i+'-3', i+'-4', i+'-5' ] );
            setTimeout( function () {
                callback( {
                    draw: data.draw,
                    data: out,
                    recordsTotal: 5000000,
                    recordsFiltered: 5000000
                } );
            }, 50 );
        scrollY: 200,
        scroller: {
            loadingIndicator: true
    } );
} );

Open in new window

But where should I put the query
Watch Question
Senior Developer
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE