目前我有这样的PHP代码(CodeIgniter):
$detail = $this->db->query("SELECT * FROM tm_survei WHERE ID_SURVEI=5")->row_array();
foreach($detail as &$val){
if (!!!$val) $val = '-'; //replace all the empty or null values with "-"
}
它解决了这个问题,但我想知道是否有可能在MySQL查询本身中做到这一点,而不需要PHP预告,例如SELECT IFNULL(*,'-') <original-column-name> FROM tm_survei
?
答案 0 :(得分:1)
$detail = $this->db->query("SELECT id, title, IFNULL(column_name1, '-'), IFNULL(column_name2, '-') as aliasname FROM tm_survei WHERE ID_SURVEI=5")->row_array();
foreach($detail as &$val){
$val;
}