该函数从数据库中获取数据,但问题是,在打印第一行后,它不会获取下一行。
请检查并告诉我我做错了什么?
Public function Return_Config($P_name, $WW, $KPI) {
log_message('debug', 'hd');
log_message('debug', $P_name . ' ' . $WW . ' ' . $KPI);
$P_name .= '_one_voice_perf_measured';
$select_query = "SELECT config FROM $P_name WHERE KPI = '$KPI' AND Config = '$WW'";
//echo $select_query;
$query = $this->db->query($select_query);
if ($query->row() > '0') {
return $query->row()->config;
} else {
return 'Not Measured';
}
}
它直接进入其他部分。请帮忙
答案 0 :(得分:2)
这是因为您使用->row()
而不是->result()
,例如:
Public function Return_Config($P_name, $WW, $KPI)
{
log_message('debug', 'hd');
log_message('debug', $P_name . ' ' . $WW . ' ' . $KPI);
$P_name.= '_one_voice_perf_measured';
$select_query = "SELECT config FROM $P_name WHERE KPI = '$KPI' AND Config = '$WW'";
// echo $select_query;
$query = $this->db->query($select_query);
if (!empty($query->result()))
{
return $query->result();
}
else
{
return 'Not Measured';
}
}
https://www.codeigniter.com/userguide3/database/results.html
的更多详情答案 1 :(得分:0)
试试这个
Public function Return_Config($P_name,$WW,$KPI){
log_message('debug','hd');
log_message('debug', $P_name.' '.$WW.' '.$KPI);
$P_name .= '_one_voice_perf_measured';
$select_query = "SELECT config FROM $P_name WHERE KPI = '$KPI' AND Config = '$WW'";
//echo $select_query;
$query = $this->db->query($select_query)->row_array();
if (!empty($query)){
return query['config'];
}
else{
return 'Not Measured' ;
}
}