1

当列出现在数据表中时,如何将空字符串转换为 Null 或“Nothing”。例如,在品牌列中,有很多空字符串。所以,我想将其更改为 null 或“无”。

$columns = array(
    array( 'db' => 'id', 'dt' => 0 ),
    array( 'db' => 'name',      'dt' => 1 ),
    array( 'db' => 'brand',     'dt' => 2 ),
    array(
        'db'        => 'end-date',
        'dt'        => 3,
        'formatter' => function( $d, $row ) {
            return date( 'jS M Y', strtotime($d));
        }
    ),
    array(
        'db'        => 'id',
        'dt'        => 4,
        'formatter' => function( $d, $row ) {
            return '<a class="btn btn-danger" href="proDelete.php?id=' . $d . '" onclick="return confirm(\'Are you sure you want to delete this item?\')">Delete</a>';
        }
    ),
);

$where = "end-date< CURDATE()";
// Include SQL query processing class
require( 'ssp.class.php' );

// Output data as json format
echo json_encode(
    SSP::complex( $_GET, $dbDetails, $table, $primaryKey, $columns, $where)
);
4

1 回答 1

0

只需像在其他列中那样使用一个函数:

array(
    'db' => 'brand',
    'dt' => 2,
    'formatter' => function($d, $row) {
        return $d !== '' ? $d : 'Nothing';
    }
),
于 2019-12-04T03:24:24.663 回答