你好,我使用表插件数据表。我将它与服务器端处理和ajax管道一起使用。
这是我实际的服务器端脚本:
<?php
// Datenbank-Tabelle, die verwendet wird
$table = 'loginlogs';
// Der Primary key, der Tabelle
$primaryKey = 'id';
// Das "datetime"-Format aus der Datenbank extrahieren, nur das Datum (in das Deutsche-Format)
function getonlydate($datetime){
$exploded = explode("-", $datetime);
$explodemeagain = explode(" ", $exploded[2]);
$mergeme = $explodemeagain[0].".".$exploded[1].".".$exploded[0];
return $mergeme;
}
// Das "datetime"-Format aus der Datenbank extrahieren, nur die Uhrzeit
function getonlytime($datetime){
$exploded = explode("-", $datetime);
$explodemeagain = explode(" ", $exploded[2]);
$mergeme = $explodemeagain[1];
return $mergeme;
}
// 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' => 'ip', 'dt' => 0 ),
array(
'db' => 'status',
'dt' => 1,
'formatter' => function( $d, $row ) {
if($d == 1){
return "Erfolgreich";
}else{
return "Fehlgeschlagen";
}
}
),
array(
'db' => 'stayloggedin',
'dt' => 2,
'formatter' => function( $d, $row ) {
if($d == 1){
return "Ja";
}else{
return "Nein";
}
}
),
array(
'db' => 'date',
'dt' => 3,
'formatter' => function( $d, $row ) {
return getonlydate($d);
}
),
array(
'db' => 'date',
'dt' => 4,
'formatter' => function( $d, $row ) {
return getonlytime($d);
}
)
);
// SQL server connection information
require('../../phpfuncs/connection.php');
$sql_details = array(
'user' => $user,
'pass' => $pw,
'db' => $db,
'host' => $host
);
require('ssp.class.php');
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
?>
现在我的问题是我如何做特定的选择?一个特定的选择,如:
"SELECT * FROM ".$table." WHERE userid=16"
我已经在他们的网站上搜索了一些文档,但我只能找到关于过滤的文档,等等。客户端的东西,但没有具体的服务器端可能性。
也许有人也使用数据表和表排序器,可以帮助我的例子?
您可以使用其他方法SSP::complex
。从代码中的注释中:
该方法与
simple
方法的区别在于可以对SQL查询应用额外的where
条件。这些都可以以以下两种形式之一:
- '结果条件' (
$whereResult
) -这应用于结果集,但不应用于总体分页信息查询-即它不会影响数量用户看到他们可以访问的记录。这应该是当您想要应用用户已发送的过滤条件时使用。- 'All condition' (
$whereAll
) -这适用于所有的查询和减少用户可以访问的记录数。这应该是在不希望用户具有访问权限的情况下使用到特定的记录(例如,通过登录id限制)。
函数接受以下参数:
SSP::complex ($request, $conn, $table, $primaryKey, $columns, $whereResult=null, $whereAll=null)
因此,为了应用具有WHERE
条件的SQL查询,您需要更改代码如下:
echo json_encode(
SSP::complex( $_GET, $sql_details, $table, $primaryKey, $columns, null, "userid=16" )
);