[eluser]the_unforgiven[/eluser]
Code: [color=blue]Controller[/color]
function clientlist()
{
// Check if user is logged in
if ($this->session->userdata('username')) {
//Pagination
$data['AutoKey'] = $this->uri->segment(3);
$data['base']=$this->config->item('base_url');
$data['title']= 'Client List';
$this->load->model("client_model");
$total = $this->client_model->client_count();
$per_pg = 20;
$offset = $this->uri->segment(3);
$config['base_url'] = $data['base'].'/admin/clientlist/';
$config['total_rows'] = $total;
$config['per_page'] = $per_pg;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['query'] = $this->client_model->get_all($per_pg,$offset);
$this->load->view('clientlist', $data);
}
else { echo '[removed]
alert("Sorry you MUST be logged in to view this page, please login!");
location = "../users";
[removed]'; }
}
Code: [color=blue]Model[/color]
function client()
{
$data['title'] = "Edit Client";
$data['success'] = $this->session->set_flashdata('success', 'The client has been successfully updated');
$data['AutoKey']=$this->uri->segment(3);
$this->db->where('AutoKey', $data['AutoKey']);
$data['query'] = $this->db->get('tblClients');
$data['query'] = $data['query']->row();
$data['meeting'] = $this->db->get('tblMeeting');
$data['meeting'] = $data['meeting']->row();
$this->load->view('editclient', $data);
}
Code: [color=blue]View[/color]
<fieldset >
<?php
$datemeet = array(
'name' => 'MeetingDate',
'value' => $meeting->MeetingDate,
'readonly' => 'readonly'
);
$timemeet = array(
'name' => 'MeetingTime',
'value' => $meeting->MeetingTime,
'readonly' => 'readonly'
);
$remarkmeet = array(
'name' => 'Remarks',
'value' => $meeting->Remarks,
'readonly' => 'readonly'
);
$cutmeet = array(
'name' => 'Cuttings',
'value' => $meeting->Cuttings,
'readonly' => 'readonly'
);
$date = array('name' => 'MeetingDate', 'id' => 'date');
$client = $query->Contact1;
if (// What should i put in here to make sure the id matches whats in the URL to grab the Meeting Data?) {
foreach ($query as $meeting)
{
?>
<table id="details">
<tr><td></td></tr>
<tr><td>Meeting Date:</td><td><?php echo form_input($datemeet); ?></td></tr>
<tr><td>Meeting Time:</td><td><?php echo form_input($timemeet); ?></td></tr>
<tr><td>Remarks:</td><td><?php echo form_textarea($remarkmeet); ?></td></tr>
<tr><td>Cuttings:</td><td><?php echo form_textarea($cutmeet); ?></td></tr>
<tr><hr /></tr>
<?php }
}
else {
echo '<div class="info">Sorry no records for this client.</div>';
}
?>
</table>
</fieldset>
The above code is what i currently having and is all working fine but in the view i have an IF statment and wish to know what I should but in the to check wether the id in the url like so http://localhost/ksd/admin/updateclient/19 <-this number matches so i can grab a table row form the the database
[eluser]vbsaltydog[/eluser]
(edited)
[eluser]Jason Stanley[/eluser]
1) You haven't shown us an updateclient controller.
2) You wouldn't do this in the view. You would do it in the controller.
Code: function something($id) {
$client = $this->client_model->single($id);
if ( ! $client) {
// Show some error
}
// Show the view file.
}
[eluser]the_unforgiven[/eluser]
Ok yes that seems to make more sense silly me:
As for the updateclient controller here it is
Code: function updateclient()
{
// Check if user is logged in
if ($this->session->userdata('username')) {
// Load Helper File
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->model('client_model');
//$info = $this->client_model->client();
// Form Validation
$this->form_validation->set_rules('Title', 'Title', 'trim|required|min_length[2]|max_length[5]|xss_clean');
$this->form_validation->set_rules('FirstName', 'First Name', 'trim|required|min_length[2]|xss_clean');
$this->form_validation->set_rules('LastName', 'Last Name', 'trim|required|min_length[2]|xss_clean');
$this->form_validation->set_rules('FullName', 'Full Name', 'trim|required|min_length[5]|xss_clean');
$this->form_validation->set_rules('Address1', 'Address1', 'trim|required|min_length[5]|xss_clean');
$this->form_validation->set_rules('Address2', 'Address2', 'trim|required|min_length[5]|xss_clean');
$this->form_validation->set_rules('Location', 'Location', 'trim|required|min_length[5]|xss_clean');
$this->form_validation->set_rules('County', 'County', 'trim|required|min_length[5]|xss_clean');
$this->form_validation->set_rules('Postcode', 'Postcode', 'trim|required|min_length[5]|max_length[7]|xss_clean');
// If validation is FALSE then return back to form
if ($this->form_validation->run() == FALSE)
{
//$this->load->view('editclient');
$this->client_model->client();
}
else
{
// Load User Model then do Function insert into DB
$this->client_model->update_client();
$this->client_model->client();
}
}
else { echo '[removed]
alert("Sorry you MUST be logged in to view this page, please login!");
location = "../users";
[removed]'; }
}
Then the two model used in that controller are here
Code: function client()
{
$data['title'] = "Edit Client";
$data['success'] = $this->session->set_flashdata('success', 'The client has been successfully updated');
$data['AutoKey']=$this->uri->segment(3);
$this->db->where('AutoKey', $data['AutoKey']);
$data['query'] = $this->db->get('tblClients');
$data['query'] = $data['query']->row();
$data['meeting'] = $this->db->get('tblMeeting');
$data['meeting'] = $data['meeting']->row();
$this->load->view('editclient', $data);
}
function update_client()
{
$data = array(
'Company'=>$this->input->post('Company'),
'Contact1'=>$this->input->post('Contact1'),
'Address1'=>$this->input->post('Address1'),
'Address2'=>$this->input->post('Address2'),
'Address3'=>$this->input->post('Address3'),
'Location'=>$this->input->post('Location'),
'County'=>$this->input->post('County'),
'Postcode'=>$this->input->post('Postcode'),
'Phone'=>$this->input->post('Phone'),
'Fax'=>$this->input->post('Fax'),
'CreditLimit'=>$this->input->post('CreditLimit'),
'Notes'=>$this->input->post('Notes'),
'DateEntered'=>$this->input->post('DateEntered')
);
$this->db->where('AutoKey', $this->uri->segment(3));
$this->db->update('tblclients', $data);
}
[eluser]the_unforgiven[/eluser]
I have tried what you said but still nothing is happening its just pulling the first piece of data rather than data relevant to that client, any idea's??
[eluser]vbsaltydog[/eluser]
Forget all of the form crap and just concentrate on the model's client function if that is where your problem is.
Code: function client()
{
$result = $this->db->get_where('tblMeeting', 'AutoKey', $this->uri->segment(3))->row();
return $result;
}
This should return your db row but judging by your code, you seem out of your depth. No offense.
[eluser]the_unforgiven[/eluser]
I may seem a little out of my depth with this little hurdle but everything else works just fine. Ill try what you said and report back!
No offense taken, but a little encourgement and support/help would be nice.
[eluser]the_unforgiven[/eluser]
So just to clarify the above code you have put goes in my client model right?
[eluser]vbsaltydog[/eluser]
The multiple errors in your code suggest that you are guessing your way through the process. It doesn't help you to encourage this tactic. If you are serious about what you are doing, you should understand why you write code a certain way. A few things that I noticed were:
You have controller logic in your model.
You were putting everything into a data array regardless of its need to be there.
Your sql logic was clearly guesswork.
You should read up on the MVC design pattern so you can understand why certain code goes in the model while other code goes in the controller. You should study the active record class if you are going to use it.
I encourage you to get better at programming but not by guessing and copy/paste. I encourage you to spend some time studying the basics before you try the advanced.
[eluser]vbsaltydog[/eluser]
[quote author="the_unforgiven" date="1328465030"]So just to clarify the above code you have put goes in my client model right?[/quote]
You shouldn't need to ask this but yes, it goes in the model's client method.
Again, read up on the basics. You can't skip crucial learning steps. That's why they are crucial.
|