Welcome Guest, Not a member yet? Register   Sign In
how update field by id, help me
#1

[eluser]hogava[/eluser]
hi.
this is my controller:

Code:
function edit()
{
  $this->load->view('edit_book_form');
  echo $id = $this->uri->segment(3);

}

function update()
{
   $data = array(
   'title' => $this->input->post('title'),
   'author' => $this->input->post('author'),
   'publisher' => $this->input->post('publisher'),
   'pagesnumber' => $this->input->post('pagesnumber')
  );
  $this->book_model->edit_book($data);
  $this->success();
}

and this is Model:

function edit_book($data) {
$this->db->from('book');
$this->db->where('id', 4);
$this->db->update('book', $data);
}

i want replace Number 4 in WHERE command with $id of edit function.
please help me
#2

[eluser]Pert[/eluser]
Quick solution without messing too much with your model structure.

a) add ID to your <strong>data</strong> variable

Code:
function edit_book($data) {
  $this->db->from(‘book’);
  if (isset($data['id'])
  {
     $this->db->where(‘id’, $data['id'])
         ->limit(1);
     $this->db->update(‘book’, $data);
   }
   else
   {
      $this->db->insert('book', $data);
   }
}

b) add ID to your model method attributes

Code:
function edit_book($data, $id = false)
{
   ...
}
#3

[eluser]hogava[/eluser]
tnx.
but my $id is on function edit() and i need it in function update()
is not it?

with ur reply: A instead of update insert new record and in B does not work.
#4

[eluser]Pert[/eluser]
<code>
function update($id = null)
{
...
}
</code>

So as with edit URL, your update URL will have ID in the end.
#5

[eluser]hogava[/eluser]
for have ID in the end of update/ how must i change form:

&lt;?php echo form_open('book/update/');?&gt;
#6

[eluser]Pert[/eluser]
[quote author="hogava" date="1370347849"]for have ID in the end of update/ how must i change form:

&lt;?php echo form_open('book/update/');?&gt;
[/quote]

Is this from the view?

Controller:
Code:
function edit()
{
   $this->load->view('edit_book_form', array('id' => $this->uri->segment(3)));
}

View:
Code:
echo form_open('book/update/'.$id);

You can change array('<strong>id</strong>' => $this->uri->segment(3)) ID to anything you want (book_id for example), in your view you will have PHP attribute with same name ($book_id)
#7

[eluser]hogava[/eluser]
Very tn:x
#8

[eluser]hogava[/eluser]
how i can load record value in edit page form? <now is empty>

i am beginner and please if can, refer a simple cms that just have build with model-view-controller files and have not other change or setting.

i am sorry for my bad English.




Theme © iAndrew 2016 - Forum software by © MyBB