【问题标题】:Datatables PHP file to exclude certain rows用于排除某些行的数据表 PHP 文件
【发布时间】:2014-12-15 14:00:28
【问题描述】:

我将以下内容与数据表一起使用,并且可以正常检索我需要的内容:

$table = 'full_data';

$primaryKey = 'index';

$columns = array(
array( 'db' => 'category',  'dt' => 0 ),
array( 'db' => 'value',  'dt' => 1 ),  
array( 'db' => 'database_percent',     'dt' => 2),
array( 'db' => 'national_percent',     'dt' => 3 ),
array( 'db' => 'index_value',     'dt' => 4 ),
  array( 'db' => 'quadrant',     'dt' => 5 )  
);

$sql_details = array(
'user' => 'root',
'pass' => '*****',
'db'   => 'my_db',
'host' => 'localhost'

);

require( 'ssp.class.php' );

echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);

我现在想做的是从该文件最终呈现为 JSON 的内容中排除行。得到我想要的 mySQL 查询是这样的:

SELECT * FROM  `full_data` WHERE  `category` NOT LIKE  'state'

但是,我不知道如何将其包含在我的 php 文件中,以便仅对正确的行进行 JSON 编码以在我的表中使用。对使用 mySQL 数据库/PHP 完全陌生。

编辑:这是我的ssp.class.php 文件。

【问题讨论】:

  • 如果没有看到你的 SSP 类实际做了什么,就不可能知道需要什么......
  • @HartmutHolzgraefe 这是我的 SSP 课程的来源:github.com/DataTables/DataTables/blob/master/examples/…
  • 您的查询 = 'state' 是因为您没有在 like 语句中添加任何“%”吗?
  • 你的数据库表是什么样子的?因为我看到你有一个索引的主键,但是你的列是 index_value?

标签: php mysql json datatables


【解决方案1】:

我确信有很多方法可以实现这一点(对于这个问题的细节很抱歉),但这是我能够做到这一点的方法。

感谢@HartmutHolzgraefe 的建议,我查看了我的 SSP 类文件并找到了这个:

// Main query to actually get the data
    $data = SSP::sql_exec( $db, $bindings,
        "SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", SSP::pluck($columns, 'db'))."`
         FROM `$table`
         $where
         $order
         $limit"
    );

我只是在此处更新了查询以匹配排除这些行所需的查询。我确实必须为此制作第二个 ssp.class.php 文件,因为我在其他几个地方使用了原始文件并且我需要它。

就像我说的,我确信有一个更好的方法来做到这一点而不是拥有两个这样的文件,但这是我能够想出的快速“破解”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多