将空字符串更改为 Null 或 "None" ssp class with PHP and Mysql
Change empty strings to Null or "None" ssp class with PHP and Mysql
当列出现在数据表中时,如何将空字符串转换为 Null 或 "Nothing"。
例如,在品牌栏中,有很多空字符串。所以,我想将其更改为 null 或 "None".
$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';
}
),
当列出现在数据表中时,如何将空字符串转换为 Null 或 "Nothing"。 例如,在品牌栏中,有很多空字符串。所以,我想将其更改为 null 或 "None".
$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';
}
),