John Davidson

php - Codeigniter click url with id to view page

0 comments
Message:


I try to get a variable working on my next page.


In controller.php I have the following:


        $buttons .= '<a href="'.base_url('klant/profiel/'.$value['id']).'" class="btn btn-default"><i class="fa fa-address-book"></i></a>'; 

And the part that is about the profiel view in controller I have this:


public function profiel($id = null) 
{
$data = $this->klant_model->getKlantData($id);

echo json_encode($data);

$this->render_template('klant/profiel', $this->data);
}

In my model I have this:


public function getKlantData($id = null)
{
if($id) {
$sql = "SELECT * FROM klant WHERE id = ?";
$query = $this->db->query($sql, array($id));
return $query->row_array();
}

$sql = "SELECT * FROM klant";
$query = $this->db->query($sql);
return $query->result_array();
}

And in my view I have this:


 <?php echo $data['bedrijf']; ?>

I just want to echo out each colum of the row I have selected in the beginning.


This error I get:


Message: Undefined variable: value


My Answer:
View';
In the above code, $row->id is passed as a parameter in the URL when the "View" link is clicked.
In the view.php file, you can retrieve this id using the following code:
php
$id = $this->uri->segment(3);

This code will get the id from the URL and store it in the $id variable. You can then use this variable to fetch data from the database or perform any other operations based on the id.

Rate this post

5 of 5 based on 5034 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us