[eluser]Unknown[/eluser]
I am developing a site where a table contains a set of question of different subjects for different classes. Registered users will be able to see the questions by selecting class or subjects from a drop down combo box.
My controller file named getAll.php is as under
Code:
<?php
class getAll extends CI_Controller {
function __construct()
{
parent::__construct();
}
function all()
{
$this->load->model('sample');
$data['q']=$this->sample->getAll();
$this->load->view('action_form',$data);
}
function select()
{
$this->load->model('sample');
$data['query']=$this->sample->getclass();
$this->load->view('select_form',$data);
}
}
Model file named sample.php is as under
Code:
<?php
class sample extends CI_Model{
function __construct() {
parent::__construct();
}
function getAll(){
$this->load->database();
$sel_class= $this->input->post('class');
$q = $this->db->query('select* from test where class=".$sel_class."');
return $q->result();
}
function getclass(){
$data = array();
$this->load->database();
$query = $this->db->query('select distinct class from test');
if ($query->num_rows() > 0) {
foreach ($query->result_array() as $row){
$data[] = $row;
}
}
$query->free_result();
return $data;
}
}
?>
I have created two view files one is select_form.php from where the users will select the class is as under
Code:
<?php
echo "<form method='post' action='http://localhost/code/CodeIgniter_2.1.0/index.php/getAll/all'>";
echo "<select name='class'>";
if (count($query)) {
foreach ($query as $key => $list) {
echo "<option value='". $list['class'] . "'>" . $list['class'] . "</option>";
}
}
echo "</select>";
echo "<input type='submit' value ='submit'/>";
echo "</form>";
?>
Another view file is action_form.php where the data on the basis of selected class will be shown. The structure of file is as under:
Code:
<?php
foreach ($q as $row)
{
print $row->id;
print $row->paper;
print $row->class;
print $row->chapter;
print $row->question;
print "</br>";
}
?>
But nothing has been shown upon selecting a class and pressing the submit button. I can't understand why its happening.
Pls Help anyone.