在get_poll
以下Poll
模型中发挥作用:
class Poll_model extends CI_Model
{
public function get_poll($parameter) {
$this->db->select('question.id, question.title, question.question, answer.answer')->from('answer')->join('question', 'answer.question_id = question_id')->where('question.id',$parameter);
$query = $this->db->get();
return $query->result_array();
}
因为我使用 join 从 2 table 和 table 中获取结果,question
并且answer
都有 column content
,所以在 result_array 中,结构如下:
Array ( [id] => 1 [title] => favourate character [content] => Green ) 1
那里只有answer content
,我认为question content
被覆盖了,因为它们都有相同的“内容”列。表结构如下图:
CREATE TABLE `answer` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`question_id` int(11) unsigned NOT NULL,
`content` text NOT NULL,
PRIMARY KEY (`id`),
KEY `question_id` (`question_id`),
CONSTRAINT `answer_ibfk_1` FOREIGN KEY (`question_id`) REFERENCES `question` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=latin1;
CREATE TABLE `question` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(128) NOT NULL DEFAULT '',
`content` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;
有没有办法解决这个问题?