Welcome Guest, Not a member yet? Register   Sign In
passing id to link?
#1

[eluser]slothdog[/eluser]
I want to delete an entry from the database by its id number. Ive got the model to do the delete working when I manually edit the function and put in the number for the id to delete.

for example:

#1 BLHABLH edit | delete

how do i get the id #1 into the link to tell the delete function what to delete?

thanks.


model:
Code:
function delete_by_pkey($idField)
{
      
      // LOAD DATABASE
      $this->load->database();
      
      // SELECT
      $this->db->where('id', $idField);

      // DO THE DELETE
      $this->db->delete('registration');

      return true;

   }

excerpt from controller:
Code:
function deletecollective()
    {
    // LOAD DATABASE MODEL
    $this->load->model('registrationmodel');
    
    // QUERY MODEL
    $data['query'] = $this->registrationmodel->delete_by_pkey(HERE IS WHERE I NEED TO GET THE ID#);
    
    // DISPLAY DATA
    $this->load->view('viewdeletecollective');
    
    }


view:
Code:
<? echo "Deleted"; ?>
#2

[eluser]manilodisan[/eluser]
Code:
$data['query'] = $this->registrationmodel->delete_by_pkey($this->uri->segment(3));

I've put uri segment 3. You should put there whatever corresponds to the id of your item.

And the link:

Code:
<a href="&lt;?= site_url ( 'controller/method/' . $id ) ?&gt;">click</a>
#3

[eluser]zimco[/eluser]
I can't tell how you're creating the links but i did something similar in a view like:
Code:
echo ('<a href="'. site_url('controller/function/'.$results[$i]['your_id']) .'">' . $results[$i]['your_id']) . '</a>');

Then do the $thedeleteid = $this->uri->segment(3, 0); thing in your delete function to know which one it is you want to delete like mailodisian already mentioned above; his post beat mine.
#4

[eluser]slothdog[/eluser]
[quote author="manilodisan" date="1224711998"]
Code:
$data['query'] = $this->registrationmodel->delete_by_pkey($this->uri->segment(3));

I've put uri segment 3. You should put there whatever corresponds to the id of your item.

And the link:

Code:
<a href="&lt;?= site_url ( 'controller/method/' . $id ) ?&gt;">click</a>
[/quote]

i tired that using the anchor() and it sent it to a function in the class with the number that didnt exist so i got a 404 error. is there a difference between using <a > and using the anchor() to make a link?
#5

[eluser]manilodisan[/eluser]
No. I tend to write html and not php to echo some html Tongue That's the only difference.
#6

[eluser]slothdog[/eluser]
thanks that worked!
#7

[eluser]Velo Studios[/eluser]
Should you not be using a form to delete?

Is it not best practice to use a form?

$data['query'] = $this->registrationmodel->delete_by_pkey($_POST['id']);




Theme © iAndrew 2016 - Forum software by © MyBB