php - datatables server side code is not working -
i have database of 56000 records whom need implement info table server side code. problem have done necessary steps accomplish task still in vain, returning me total set of data.
the main problem when page loads loads 56000 records on runtime , cause page halt in non ending state.
so, 1 time info table implemented problem goes automatically. want operation done on run time. 1 time page loads, should show pagination , split 56000 records in paging pages. limit should 50.
the search , sorting not working.
here js function:
<link href="//cdn.datatables.net/1.10.0/css/jquery.datatables.css" rel="stylesheet" type="text/css" /> <script src="http://legacy.datatables.net/release-datatables/media/js/jquery.js"></script> <script src="//legacy.datatables.net/release-datatables/media/js/jquery.datatables.js"></script> <script type="text/javascript" language="javascript" class="init"> $(document).ready(function() { $('#rounded-corner').datatable( { "processing": true, "serverside": true, "ajax": "<?php echo web_url; ?>assets/common/authorsserverside.php", } ); } ); </script> here html code:
<table id="rounded-corner" summary="2007 major companies' profit" class="display" cellspacing="0" width="100%"> <thead> <tr> <th scope="col" class="rounded-company">sr no.</th> <th scope="col" class="rounded">author name</th> <th scope="col" class="rounded">birth year</th> <th scope="col" class="rounded">death year</th> <th scope="col" colspan="2" class="rounded-q4">action</th> </tr> </thead> <tbody> <?php $count = 1; while($authorrecs = $recordset->fetch_object()){?> <tr> <td><?php echo $count++; ?></td> <td><?php print stripslashes(html_entity_decode($authorrecs->a_name)); ?></td> <td><?php print $authorrecs->a_birth; ?></td> <td><?php print $authorrecs->a_death; ?></td> <td><a href="editauthors?a_id=<?php echo $authorrecs->a_id; ?>"><img src="../assets/styles/admin/images/user_edit.png" alt="" title="" border="0" /></a></td> <td><a href="process/adminprocess.php?page=deleteauthors&a_id=<?php echo $authorrecs->a_id; ?>" class="ask"><img src="../assets/styles/admin/images/trash.png" alt="" title="" border="0" /></a></td> </tr> <?php } ?> </tbody> </table> and server side code:
<?php /* * script: datatables server-side script php , mysql * copyright: 2010 - allan jardine, 2012 - chris wright * license: gpl v2 or bsd (3-point) */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * easy set variables */ /* array of database columns should read , sent datatables. utilize space * want insert non-database field (for illustration counter or static image) */ $acolumns = array( 'a_id', 'a_name', 'a_birth', 'a_death' ); /* indexed column (used fast , accurate table cardinality) */ //$sindexcolumn = "a_id"; /* db table utilize */ $stable = "authors"; /* database connection info */ $gasql['user'] = "root"; $gasql['password'] = ""; $gasql['db'] = "giftcardbooks"; $gasql['server'] = "localhost"; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * if want utilize basic configuration datatables php server-side, there * no need edit below line */ /* * local functions */ function fatal_error ( $serrormessage = '' ) { header( $_server['server_protocol'] .' 500 internal server error' ); die( $serrormessage ); } /* * mysql connection */ if ( ! $gasql['link'] = mysql_pconnect( $gasql['server'], $gasql['user'], $gasql['password'] ) ) { fatal_error( 'could not open connection server' ); } if ( ! mysql_select_db( $gasql['db'], $gasql['link'] ) ) { fatal_error( 'could not select database ' ); } /* * paging */ $slimit = ""; if ( isset( $_get['idisplaystart'] ) && $_get['idisplaylength'] != '-1' ) { $slimit = "limit ".intval( $_get['idisplaystart'] ).", ". intval( $_get['idisplaylength'] ); } /* * ordering */ $sorder = ""; if ( isset( $_get['isortcol_0'] ) ) { $sorder = "order "; ( $i=0 ; $i<intval( $_get['isortingcols'] ) ; $i++ ) { if ( $_get[ 'bsortable_'.intval($_get['isortcol_'.$i]) ] == "true" ) { $sorder .= $acolumns[ intval( $_get['isortcol_'.$i] ) ]." ".($_get['ssortdir_'.$i]==='asc' ? 'asc' : 'desc') .", "; } } $sorder = substr_replace( $sorder, "", -2 ); if ( $sorder == "order by" ) { $sorder = ""; } } /* * filtering * note not match built-in datatables filtering * word word on field. it's possible here, concerned efficiency * on big tables, , mysql's regex functionality limited */ $swhere = ""; if ( isset($_get['ssearch']) && $_get['ssearch'] != "" ) { $swhere = "where ("; ( $i=0 ; $i<count($acolumns) ; $i++ ) { if ( isset($_get['bsearchable_'.$i]) && $_get['bsearchable_'.$i] == "true" ) { $swhere .= $acolumns[$i]." '%".mysql_real_escape_string( $_get['ssearch'] )."%' or "; } } $swhere = substr_replace( $swhere, "", -3 ); $swhere .= ')'; } /* individual column filtering */ ( $i=0 ; $i<count($acolumns) ; $i++ ) { if ( isset($_get['bsearchable_'.$i]) && $_get['bsearchable_'.$i] == "true" && $_get['ssearch_'.$i] != '' ) { if ( $swhere == "" ) { $swhere = "where "; } else { $swhere .= " , "; } $swhere .= $acolumns[$i]." '%".mysql_real_escape_string($_get['ssearch_'.$i])."%' "; } } /* * sql queries * info display */ $squery = " select sql_calc_found_rows ".str_replace(" , ", " ", implode(", ", $acolumns))." $stable $swhere $sorder $slimit "; $rresult = mysql_query( $squery, $gasql['link'] ) or fatal_error( 'mysql error: ' . mysql_errno() ); /* info set length after filtering */ $squery = " select found_rows() "; $rresultfiltertotal = mysql_query( $squery, $gasql['link'] ) or fatal_error( 'mysql error: ' . mysql_errno() ); $aresultfiltertotal = mysql_fetch_array($rresultfiltertotal); $ifilteredtotal = $aresultfiltertotal[0]; /* total info set length */ $squery = " select count(".$sindexcolumn.") $stable "; $rresulttotal = mysql_query( $squery, $gasql['link'] ) or fatal_error( 'mysql error: ' . mysql_errno() ); $aresulttotal = mysql_fetch_array($rresulttotal); $itotal = $aresulttotal[0]; /* * output */ $output = array( "secho" => intval($_get['secho']), "itotalrecords" => $itotal, "itotaldisplayrecords" => $ifilteredtotal, "aadata" => array() ); while ( $arow = mysql_fetch_array( $rresult ) ) { $row = array(); ( $i=0 ; $i<count($acolumns) ; $i++ ) { if ( $acolumns[$i] == "version" ) { /* special output formatting 'version' column */ $row[] = ($arow[ $acolumns[$i] ]=="0") ? '-' : $arow[ $acolumns[$i] ]; } else if ( $acolumns[$i] != ' ' ) { /* general output */ $row[] = $arow[ $acolumns[$i] ]; } } $output['aadata'][] = $row; } echo json_encode( $output ); ?>
looks lastly line of datatable function has comma. ","
php datatable datatables jquery-datatables
No comments:
Post a Comment