in get_poll function in following Poll model:
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();
}
Because I’m using join to get result from 2 table and table question and answer both have column content, so in the result_array, the structure like this:
Array ( [id] => 1 [title] => favourate character [content] => Green ) 1
The there’s only answer content, I think the question content was overwrite, because both of them have the same column ‘content’. the table structure shown below:
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;
Is there any way to solve this problem?
Simply rename the columns inside the
->select()call like this:The result rows now should contain a
questionand aanswerindex.