[eluser]ede196620[/eluser]
So i have this application where i have a list of questions that have to be selected and then answered the questions are not related to each other they are individual displayed. What i have is a
links that display question that are generated from the database and when the link is clicked it should take the user to the question that he will answer.
currently i have this view
Code:
<div>
<h1> <?php
foreach($query as $row){
echo anchor('survaycontroller', $row->Question);
echo '<br>';
}
?></h1>
</div>
and this controller for the questions
Code:
<?php
class Survaycontroller extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('survay');
}
function index() {
$data = array();
$question_id = $this->uri->segment(3);
$data['survay_data'] = $this->survay->dosurvay($question_id);
$this->load->view('survay_view', $data);
}
function addanswer() {
$arrData = array();
$userid = null;
if ($this->session->userdata("userid")) {
$userid = $this->session->userdata("userid");
}
if ($this->input->post()) {
//$arrData["answerid"] = $this->input->post("QID");
$arrData["questionid"] = $this->input->post("qA");
if ($this->input->post("qA")) {
$arrData["answerA"] = $this->input->post("qA");
}
if($this->input->post("qB")) {
$arrData["answerB"] = $this->input->post("qB");
}
if($this->input->post("qC")) {
$arrData["answerC"] = $this->input->post("qC");
}
$arrData["comment"] = $this->input->post("comment");
$arrData["userid"] = $userid;
}
$viewData['survay_data_id'] = $this->survay->addsurvay($arrData);
$this->load->view('survay_view', $viewData);
redirect('end');
}
}
?>
this is the part where i am stuck i cant figure out how to display the question with optional answers with the corresponding anchor link. I tried to research this but could not find anything on this topic.
o and here is the view for the question section:
Code:
<body>
<?php if(isset($survay_data)) : ?>
<form acti name="myform" id="myform" method="post">
<?php foreach ($survay_data as $survay): ?>
<ul>
<li><h1><?php echo $survay->Question; ?></h1></li>
<li><?php echo $survay->qA; ?><input type="checkbox" name="qA" value="<?php echo $survay->qA; ?>"></li>
<li><?php echo $survay->qB; ?><input type="checkbox" name="qB" value="<?php echo $survay->qB; ?>"></li>
<li><?php echo $survay->qC; ?><input type="checkbox" name="qC" value="<?php echo $survay->qC; ?>"></li>
Comment:
<li><?php echo form_textarea('comment')?> </li>
<li><input type="hidden" name="QID" value="<?php echo $survay->QID; ?>"></li>
<li><input type="submit" name="btn" value="Answer"></li>
</ul>
<?php endforeach; ?>
</form>
<?php endif; ?>
</body>
I am still very new to codeigniter and cant figure this out any help would be greatly appreciated.
Would the solution be similar to this example :
Code:
function view($id){
// set common properties
$data['title'] = 'Question Details';
$data['link_back'] = anchor('display/index/','List Of Questions',array('class'=>'back'));
// get Question details
$data['query'] = $this->display_model->get_by_id($id)->row();
// load view
$this->load->view('viewquestion', $data);
}
tnx for the guidance.