我正在尝试使用CodeIgniter执行以下查询,但我正在
未知的索引 - > row ['code'];
public function getSExtension($id) {
$temp = array();
$query = $this->db->query("SELECT extension_id FROM " . DB_PREFIX . "zipcode_shipping WHERE `zip_code` = '" . $id . "'");
if($query->num_rows) {
foreach ($query->rows as $key => $value) {
$code = $this->db->query("SELECT code FROM " . DB_PREFIX . "extension WHERE `extension_id` = '" . $value['extension_id'] . "'")->row['code'];
$this->language->load("shipping/".$code);
$temp[] = $this->language->get('text_title');
}
}
return $temp;
}
答案 0 :(得分:0)
问题是您没有正确检索需要方法调用的结果集。如你所知,你试图使用不存在的db属性,即$query->rows
应该是$query->row_array()
。
在下面的示例中,我使用result()
和row()
代替任何“数组”方法。
试试这个。
$temp = array();
$query = $this->db->query("SELECT extension_id FROM ".DB_PREFIX."zipcode_shipping WHERE `zip_code` = '".$id."'");
if($query->num_rows() > 0)
{
foreach($query->result() as $value)
{
$code = $this->db->query("SELECT code FROM ".DB_PREFIX."extension WHERE `extension_id` = '".$value->extension_id."'")->row()->code;
$this->language->load("shipping/".$code);
$temp[] = $this->language->get('text_title');
}
}