如何通过ssp.class.php数据表使用'WHERE'子句 [英] How to use 'WHERE' clause using ssp.class.php DataTables

查看:144
本文介绍了如何通过ssp.class.php数据表使用'WHERE'子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我尝试使用jQuery DataTable(DataTables.net)显示数据库中的信息。
我可以正常显示整个表格的笔记,但是我只想显示未读的笔记。因此,我需要以某种方式包括WHERE子句,但是我不清楚实现此目的的最佳方法。

Okay so i'm trying to display information from my database using jQuery DataTable (DataTables.net). I can get it to work fine displaying the entire table 'notes' but I would like to just display notes that have not been read. So I need to include a WHERE clause somehow but i'm unclear on the best way to go about this.

这是我当前显示整个表格的方式:

Here is how I currently display the whole table:

// 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'        => 0,
    'formatter' => function( $d, $row ) {
        return '<a href="profile.php?search='.$d.'" target="_Blank">'.$d."</a>";
    }
),

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 '

推荐答案

您应该更改 DataTables 默认功能来做到这一点!

You should change DataTables default functions to do this!

使用此 ssp.class.php 自定义类

链接

使用它,例如以下示例:

Use it like following example:

require( 'ssp.class.php' );
$where = "Status ='Unread'";
echo json_encode(
    SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns,$where )
);

如果设置$ where参数,则Custom类将添加where子句以选择语句!

If you set $where parameter, Custom class will add where clause to select statement!

更新

2015年的数据表添加了复杂的方法

DataTables in 2015 add complex method

新的内置方法可以设置where子句正在查询!

The new built-in method can set where clause in query!

这篇关于如何通过ssp.class.php数据表使用'WHERE'子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆