troubleshooting Question

How to do server-side processing

Avatar of Jazzy 1012
Jazzy 1012 asked on
HTMLPHP* datatabes
4 Comments1 Solution416 ViewsLast Modified:
I have this datatable:
<table class="table table-striped" id="sales-order-table">
	<thead>
		<tr>
			<th> ID</th>
			<th>Name</th>
			<th> Last Name</th>
			<th>Email</th>
			<th>Order</th>
			<th>Date</th>
			<th>Status</th>
			<th>Option ID</th>
			<th>Meal Name</th>
			<th>Amount</th>
			<th>Quantity</th>
		</tr>
	</thead>
	<tbody>
<?php 
	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)
	{
		continue;
	}
	else{
	$row_to_get_info = mysqli_fetch_assoc($result_to_get_info);
	?>
	<tr>
		<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>

		</tr>
		<?php }
		}?>
	</tbody>
</table>
<script>
$(document).ready(function(){
    $('#sales-order-table').DataTable({
        "pageLength": 50,
        dom: 'Bfrtip',
        buttons: [
                  {
                	  extend: 'csv', text: 'Download CSV' }
        ]
    });
});
</script>

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
        }
    } );
} );

But where should I put the query
ASKER CERTIFIED SOLUTION
ste5an
Senior Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros