php - 使用 PHP 和 Mysql 将空字符串更改为 Null 或 "None"ssp 类

标签 php mysql ssp

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

最佳答案

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

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

关于php - 使用 PHP 和 Mysql 将空字符串更改为 Null 或 "None"ssp 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59168424/

相关文章:

php - php中的mysql查询具有来自两个表的更多条件

mysql - 如何在 ssp 简单类中使用 UNION ALL?

c - 使用 DMA 读取 SPI (SSP) 总线上的 EEPROM

php - 如何阻止PHP输出缓冲区超过内存限制?

php - 图片上传失败

php - 使用 PHP 更新数据库时出错

mysql - SQL 如何用单个默认文本替换文本列中的所有(可变)文本?

php - mysql:连接正常但响应错误

javascript - 具有相同名称的多个选择输入 Laravel