[eluser]Unknown[/eluser]
This is my controller code
Code:
/*************************** Begin Add state ****************************/
function state() {
$this->load->view('admin/state');
$data['states'] = $this->master_model->getState();
}
function addNewState() {
$this->load->view('admin/addstate');
}
function addState() {
$this->load->library('form_validation');
$this->form_validation->set_rules('st_StateName','State Name','required');
if($this->form_validation->run() == false) {
$this->load->view('admin/addstate');
}
else {
$this->master_model->createNewState();
echo "State Name added Successfully";
}
}
/*************************** End Add state ****************************/
My model code is
Code:
function createNewState() {
$data = array(
'st_StateName' => $this->input->post('st_StateName'),
'st_ActiveStatus' => $this->input->post('st_ActiveStatus')
);
return $result= $this->db->insert('crm_state_master', $data);
}
function getState() {
$this->db->select('st_StateName, st_ActiveStatus');
$this->db->from('crm_state_master');
$query = $this->db->get();
$queryResult = $query->result();
return $queryResult;
}
And this is my view code
Code:
<table align='center' width='100%' id="gradient-style">
<tr>
<td colspan="7">State Information |<?php echo anchor('master/addNewstate', 'ADD NEW STATE'); ?></td>
</tr>
<tr>
<th>State Name</th>
<th>Access Level</th>
<th>Edit</th>
</tr>
<?php
if(is_array($data)) {
foreach($data as $value): ?>
<tr>
<td><?php echo $value->st_StateName;?></td>
<td><?php echo $value->st_ActiveStatus;?></td>
<td><a href="edit/<?php echo $value->sr_Id; ?>">Edit</a></td>
</tr>
<?php endforeach;
}
?>
</table>
I get an error called "Undefined variable: data"
Please help me on this...