Welcome Guest, Not a member yet? Register   Sign In
newbie stuck on set_value
#1

[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>
&lt;?php $alternate = "2"; ?&gt;
&lt;?php foreach ($phonelist as $row):  ?&gt;

&lt;?php if ($alternate == "1") {
$color = "#00ffff";
$alternate = "2";
}
else {
$color = "#efefef";
$alternate = "1";
} ?&gt;

<tr bgcolor=&lt;?=$color?&gt;>    

<td>&lt;?=$row['LAST_NAME']?&gt;</td>
<td>&lt;?=$row['FIRST_NAME']?&gt;</td>
<td>&lt;?=$row['DEPARTMENT']?&gt;</td>
<td>&lt;?=$row['EXTENSION']?&gt;</td>
<td nowrap>&lt;?=$row['CELLPHONE#']?&gt;</td>
<td nowrap>&lt;?=$row['PAGER']?&gt;</td>
<td><a href="P:\Human Resources\Employee Pictures - Sept 2005/&lt;?=$row['USERIMAGE']?&gt;"><img src=" P:\Human Resources\Employee Pictures - Sept 2005/thumbs/tn_&lt;?=$row['USERIMAGE']?&gt;"> </a></td>

<td>&lt;?=anchor('phonelist/edit_phone/'.$row['ID'], 'Edit Record')?&gt;</td>
</tr>  
&lt;?php endforeach; ?&gt;
</tbody>
</table>
&lt;/body&gt;
&lt;/html&gt;
phone_edit- view
Code:
&lt;?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' ).'&nbsp;&nbsp;';
echo form_input(set_value($phonelist->LAST_NAME)).'<br />' ;
echo form_label('First Name', 'First' ).'&nbsp;&nbsp;';
echo form_input('FIRST_NAME').'<br />' ;

Thanks
#2

[eluser]M Moeen uddin[/eluser]
Well actually, i m right now having the same problem.
Actually, the variables $row['LAST_NAME'] etc are not defined here. So a temporary solution would be to set

if(!edit){
$row['LAST_NAME']='';
...

}else{
get_the_row records
}

... Well, thats dirty, but hopefully works.Otherwise i m working out on this more
#3

[eluser]TheFuzzy0ne[/eluser]
The first parameter of set_value() should be the name of the field. In your case, the input field doesn't have a name (but needs one). The second parameter for set_value() is the one you wish to show if the field you specified in the first parameter, is not set in the post array (i.e the form hasn't been submitted).




Theme © iAndrew 2016 - Forum software by © MyBB