[eluser]buckboru[/eluser]
I've been fooling around with creating a little phone list application that displays employees in a list and has an edit/delete function that can be selected on each employee.
I am stuck on editing the data(i guess i will use the same view to add a record also, I just haven't gotten that far.
It seems I read that in order for the data to show I have to use validation(but maybe i miss understood). I'm hoping someone can help me figure out what i'm doing wrong. I'm currently getting 'trying to get property of non-object.
I'm only trying to load last name currently- until i get it figured out.
Also, in case its confusing. I'm connecting to a DB2 database and in order for me to access the fields, they have to be in CAPS.
here is code
Controller Phonelist
Code:
<?php
class Phonelist extends Controller
{
function phonelist()
{
parent::Controller();
//this gives us redirect
$this->load->helper('url');
$this->load->database();
$this->load->model('phone_model');
$this->load->helper('form');
$this->load->library('form_validation');
}
function list_users()
{
$this->load->model('phone_model');
$data['phonelist'] = $this->phone_model->get_phonelist();
$this->load->view('phonelist_view', $data);
}
function edit_phone($id = false)
{
$this->form_validation->set_rules('LAST_NAME', '', '');
if (!$id) redirect ('phonelist/list_users');
$data['phonelist'] = $this->phone_model->get_phone($id);
$this->load->view('phone_edit',$data);
}
}
phonelist_view
Code:
<html>
<body>
<?php $alternate = "2"; ?>
<table border="1" style="border-collapse: collapse;">
<thead>
<tr ><td><u>Last Name</u></td>
<td><u>First Name</u></td>
<td><u>Dept</u></td>
<td><u>Extension</u></td>
<td nowrap ><u>Cell Phone</u></td>
<td><u>Pager</u></td>
<td><u>Photo</u></td></tr>
</thead>
<tbody>
<?php $alternate = "2"; ?>
<?php foreach ($phonelist as $row): ?>
<?php if ($alternate == "1") {
$color = "#00ffff";
$alternate = "2";
}
else {
$color = "#efefef";
$alternate = "1";
} ?>
<tr bgcolor=<?=$color?>>
<td><?=$row['LAST_NAME']?></td>
<td><?=$row['FIRST_NAME']?></td>
<td><?=$row['DEPARTMENT']?></td>
<td><?=$row['EXTENSION']?></td>
<td nowrap><?=$row['CELLPHONE#']?></td>
<td nowrap><?=$row['PAGER']?></td>
<td><a href="P:\Human Resources\Employee Pictures - Sept 2005/<?=$row['USERIMAGE']?>"><img src=" P:\Human Resources\Employee Pictures - Sept 2005/thumbs/tn_<?=$row['USERIMAGE']?>"> </a></td>
<td><?=anchor('phonelist/edit_phone/'.$row['ID'], 'Edit Record')?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>
phone_edit- view
Code:
<?php
echo anchor('/phonelist/list_users' , 'Back To List');
echo form_open('/phonelist/edit_form/'.$this->uri->segment(3) );
echo form_label('Last Name', 'Last' ).' ';
echo form_input(set_value($phonelist->LAST_NAME)).'<br />' ;
echo form_label('First Name', 'First' ).' ';
echo form_input('FIRST_NAME').'<br />' ;
Thanks