【问题标题】:Change empty strings to Null or "None" ssp class with PHP and Mysql使用 PHP 和 Mysql 将空字符串更改为 Null 或“None”ssp 类
【发布时间】:2020-03-28 19:22:50
【问题描述】:

当列出现在数据表中时,如何将空字符串转换为 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)
);

【问题讨论】:

    标签: php mysql ssp


    【解决方案1】:

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

    array(
        'db' => 'brand',
        'dt' => 2,
        'formatter' => function($d, $row) {
            return $d !== '' ? $d : 'Nothing';
        }
    ),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-04
      • 1970-01-01
      相关资源
      最近更新 更多