[eluser]eironotics[/eluser]
Hi mellis,
First of all thanks,to make it clearer to you heres my code.
please help me im completely new with CI.
Controller Contacts
Code:
class Contacts extends controller{
function Contacts(){
parent:: Controller();
$this->load->database();
$this->load->model('contacts_model');
$this->load->helper('form');
$this->load->scaffolding('contacts');
;
}
function index(){
$data['title']="Displaying all Contacts";
$data['query']=$this->contacts_model->poplist();
$data['insert']=0;
$this->load->view('contacts_view',$data);
}
function popEditWindow(){
//pass to array
$arrayid= $this->input->post('edit');
if(count($arrayid)){
for($i=0;$i<=count($arrayid); $i++){
//call model to compare
$id= $arrayid[$i];
echo $id;
//call the view for display
}
}
else{
echo 'No selected';
}
}
function popInsertWindow(){
$data['title']="Inserting New Contacts";
$data['insert']=1;
$this->load->view('contacts_view',$data);
}
function insertDB(){
$data['query']= $this->contacts_model->insertlist();
if($data['query']){
redirect('contacts/index');
}
}
}
?>
Views: Contacts_view: it is used for inserting and popping the data in the table
Code:
<body>
<p align=center><?=$title ?></p>
<hr align= "center" width="650px">
<?php
if($insert==1){
echo '<div align=center>';
echo form_open('contacts/insertDB');
echo ' Name:'.form_input('name');
echo 'Phone:'.form_input('phone');
echo 'Email:'.form_input('email');
echo '<input type= submit value=Save >';
echo form_close();
echo '<div>';
}
else{
?>
<?php
?>
<p align="center">
<?php
echo anchor('contacts/popInsertWindow','New ');
?>
<table border=0 align="center" width="650px">
<tr bgcolor="#e3e3e3">
<td></td>
<td>ID</td>
<td>Full Name</td>
<td>Phone</td>
<td>Email</td>
</tr>
<?php
echo form_open('contacts/popEditWindow');
foreach ($query->result() as $row){
echo '<tr><td>'.form_checkbox('edit[]',$row->id);
echo '<td>'.$row->id.'</td><td>'.$row->name.'</td><td>'.$row->phone.
'</td><td>'.$row->email.'</td></tr>';
}
?>
<tr>
<td></td>
<td>
</td>
<td>
<?php
echo form_submit('editbutton','Edit');
echo form_close();
?>
</td>
<td></td>
<td></td></td>
</tr>
</table>
<?php
}
?>
Model: contacts_model
Code:
class contacts_model extends Model{
function contacts_model(){
parent::Model();
}
function poplist(){
$this->db->orderby('id','DESC');
$query=$this->db->get('contacts');
return $query;
}
function insertlist(){
$query = $this->db->insert('contacts',$_POST);
return $query;
}
function compareID($id){
$query = $this->db->get_where('contacts', array('id' => $id));
return $query;
}
}
the probleM:
how can i populate the data from the table and fill it in the form.
and how to update the table based from the specified ID number from that form
when the update button is submitted
help me.pls.