|
好吧,所以我试着用它,所以我试着用它jQuery
2 X6 C% M) F6 U5 h! F( I$ m/ I3 YDataTable(DataTables.net)从我的数据库中显示信息。我可以很好地显示整个表的注释,但我只想显示未读的注释。因此,我需要以某种方式包括它WHERE但我不知道实现这一目标的最好方法。
4 _; F) K6 s) c0 k0 j& I+ S这是我目前展示整个表格的方式:5 w3 W5 H {9 ]0 n p! l* g
// DB table to use$table = 'Notes';// Table's primary key$primaryKey = 'CID';// Array of database columns which should be read and sent back to DataTables.// The `db` parameter represents the column name in the database,while the `dt`// parameter represents the DataTables column identifier. In this case simple// indexes$columns = array(array( 'db' => 'CID','dt' => 0 ),array( db => 'CID', 'dt => formatter' => function( $d,$row ()()()()()return '[url=profile.php?search='.$d.']'.$d."[/url]"; array( 'db' => 'Title','dt' => 1 ),array( 'db' => 'Name', 'dt' => 2 ),array( 'db => 'Date dt => 3、 formatter' => function( $d,$row ()()()()()return date( 'jS M y',strtotime($d)); )SQL server connection information$sql_details = array('user' => '*DB_USER*','pass' => '*Password*','db' => '*DatabaseName*','host' => 'localhost');require( 'ssp.class.php' );echo json_encode( SSP::simple( $_GET,$sql_details,$table,$primaryKey,$columns ));我需要相当于 SELECT * FROM Notes WHERE Status ='Unread'
# U6 j5 F9 E. L# ~4 Z6 x
+ c" N6 j; w! C 解决方案: ( p- C# @$ Y; Z/ Z6 q0 }( q
您应该更改 DataTables的 默认功能做到这一点!8 K( q! V" R7 x( A1 P
使用此 ssp.class.php 定制类. u9 x: j/ D! l. M
关联7 q, w! f: h$ n" H" w+ m: \
就像下面的例子一样:
4 f' J0 S/ y6 T' n. _- drequire( 'ssp.class.php' );$where = "Status ='Unread'";echo json_encode( SSP::simple( $_GET,$sql_details,$table,$primaryKey,$columns,$where ));如果设置$ where参数,则Custom类将在where子句中添加select语句!
3 f7 w" ^- @: I# }2 c/ g% W( F" o更新 :
9 e* X3 q( A& g# }, F, S& j2015年DataTables添加复杂的方法; c- s4 L: P, s2 L5 X, g
可以在查询中设置新的内置方法where子句! |
|