annotate DataTables-1.9.4/examples/examples_support/infiniteScroll.php @ 9:7300ed4c1481 draft default tip

Uploaded
author saskia-hiltemann
date Mon, 04 Sep 2017 10:49:00 -0400
parents ac5f9272033b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
1 <?php
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
2 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
3 * Easy set variables
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
4 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
5
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
6 /* Array of database columns which should be read and sent back to DataTables. Use a space where
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
7 * you want to insert a non-database field (for example a counter or static image)
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
8 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
9 $aColumns = array( 'name', 'phone', 'email', 'city', 'zip' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
10
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
11 /* Indexed column (used for fast and accurate table cardinality) */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
12 $sIndexColumn = "id";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
13
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
14 /* DB table to use */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
15 $sTable = "testData";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
16
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
17 /* Database connection information */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
18 $gaSql['user'] = "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
19 $gaSql['password'] = "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
20 $gaSql['db'] = "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
21 $gaSql['server'] = "localhost";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
22
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
23 /* REMOVE THIS LINE (it just includes my SQL connection user/pass) */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
24 include( $_SERVER['DOCUMENT_ROOT']."/datatables/mysql.php" );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
25
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
26
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
27 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
28 * If you just want to use the basic configuration for DataTables with PHP server-side, there is
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
29 * no need to edit below this line
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
30 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
31
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
32 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
33 * MySQL connection
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
34 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
35 $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
36 die( 'Could not open connection to server' );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
37
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
38 mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
39 die( 'Could not select database '. $gaSql['db'] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
40
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
41
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
42 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
43 * Paging
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
44 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
45 $sLimit = "";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
46 if ( isset( $_GET['iStart'] ) && isset( $_GET['iLength'] ) )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
47 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
48 $sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iStart'] ).", ".
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
49 mysql_real_escape_string( $_GET['iLength'] );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
50 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
51 else
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
52 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
53 echo '{ "aaData": [] }';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
54 exit();
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
55 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
56
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
57 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
58 * SQL queries
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
59 * Get data to display
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
60 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
61 $sQuery = "
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
62 SELECT ".str_replace(" , ", " ", implode(", ", $aColumns))."
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
63 FROM $sTable
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
64 ORDER BY name ASC
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
65 $sLimit
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
66 ";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
67 $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
68
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
69 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
70 * Output
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
71 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
72 $sOutput = '{';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
73 $sOutput .= '"aaData": [ ';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
74 while ( $aRow = mysql_fetch_array( $rResult ) )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
75 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
76 $sOutput .= "[";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
77 for ( $i=0 ; $i<count($aColumns) ; $i++ )
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
78 {
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
79 /* General output */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
80 $sOutput .= '"'.str_replace('"', '\"', $aRow[ $aColumns[$i] ]).'",';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
81 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
82
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
83 /*
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
84 * Optional Configuration:
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
85 * If you need to add any extra columns (add/edit/delete etc) to the table, that aren't in the
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
86 * database - you can do it here
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
87 */
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
88
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
89
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
90 $sOutput = substr_replace( $sOutput, "", -1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
91 $sOutput .= "],";
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
92 }
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
93 $sOutput = substr_replace( $sOutput, "", -1 );
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
94 $sOutput .= '] }';
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
95
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
96 echo $sOutput;
ac5f9272033b first upload
saskia-hiltemann
parents:
diff changeset
97 ?>