how to populate values in dropdown from database in codeigniter

#1
[eluser]Unknown[/eluser]
Hi all,
I am new to codeigniter. I am trying to make a form with 2 dropdownlist, 2 textbox and 4 checkbox for crud operations. The process in the form is first dropdownlist named "user" should be automatically loaded, after selecting user dropdownlist, second dropdownlist named "client" should be loaded. and with the value selected in client dropdown, textbox "process" should be retrieved. . user dropdownlist values should be automatically loaded from database. I could retrieve it. It doesn't call model file. Pls help how to generate values in dropdown. I have written coding for first dropdown alone. Give some ideas..

My model page Sadprojdet.php)
<?php
class Projdet extends CI_Model
{
function projdet()
{
$query = "select distinct user from sproject";
$res = $this->db->query($query);
return $res->result();
}
/*function get_proj_value()
{
$query = $this->db->get('sproject');
if($query->num_rows()>0)
{
$query_result = $query->result_array();
return $query_result();
}
else
return FALSE;
}*/
}
?>

my view page : (home_view.php)

<html>
<head>
<title>Simple Login with CodeIgniter - Private Area</title>

</head>
<body>
<p align="right">Welcome &lt;?php echo $username; ?&gt;!,,<a href="home/logout">Logout</a></p>
<table align="center" border="1">
&lt;?php echo validation_errors(); ?&gt;
&lt;?php echo form_open('home/view'); ?&gt;
&lt;?php //$user = array('name'=>'user','id'=>'user','value'=>'$this->projdet->projdet()')?&gt;

<tr><td>User List : </td>
<td><select name="users">
&lt;?php foreach($this->projdet->projdet() as $tagData): ?&gt;
<option>&lt;?php echo $tagData->user; ?&gt;</option>&lt;?php endforeach; ?&gt;
</select></td></tr>


<tr><td>Client List :</td>
<td><select name="client">
<option></option>
</select></td>
<td align="center" colspan="4">CRUD Operations</td></tr>

<tr><td>Process1 : </td>
<td>&lt;input type="text" name="process" id="process"/&gt;&lt;/td>
<td>&lt;input type="checkbox" name="view"/&gt;View</td>
<td>&lt;input type="checkbox" name="update"/&gt;Update</td>
<td>&lt;input type="checkbox" name="create"/&gt;Create</td>
<td>&lt;input type="checkbox" name="delete"/&gt;Delete</td></tr>

<tr><td>Process2 : </td>
<td>&lt;input type="text" name="process" id="process"/&gt;&lt;/td>
<td>&lt;input type="checkbox" name="view"/&gt;View</td>
<td>&lt;input type="checkbox" name="update"/&gt;Update</td>
<td>&lt;input type="checkbox" name="create"/&gt;Create</td>
<td>&lt;input type="checkbox" name="delete"/&gt;Delete</td></tr>

</table>
&lt;?php echo form_close(); ?&gt;
&lt;/body&gt;
&lt;/html&gt;


my controller page Sadhome.php)

&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
class Home extends CI_Controller {

function __construct()
{
parent::__construct();
$this->load->model('projdet');
}

function index()
{
if($this->session->userdata('logged_in'))
{
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
$this->load->view('home_view', $data);
}
else
{
//If no session, redirect to login page
redirect('login', 'refresh');
}
}

function logout()
{
$this->session->unset_userdata('logged_in');
session_destroy();
redirect('home', 'refresh');
}
function view()
{
$this->load->model('projdet');
$result = $this->projdet->projdet();
}
/*function get_values_json()
{
$proj = $this->Projdet->get_proj_value();
$json_encode_list = json_encode($proj);
echo $json_encode_list;
}*/
}

?&gt;



Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.