CodeIgniter Forums
How do I echo datase id in base url? CI4? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forum-10.html)
+--- Thread: How do I echo datase id in base url? CI4? (/thread-78936.html)



How do I echo datase id in base url? CI4? - olumideaeo - 03-29-2021

I am trying to edit user-specific information from the database using id. I have used a hidden input field for the user id but want to assign it so the form can load each user's details.

I have assigned the value of the hidden user-id field in the controller. What will be the proper syntax to edit the id using the Edit button. The method and controller work fine but not bring out user-specific form I linked to the method. I have used [color=#333333][size=small][font=Tahoma, Verdana, Arial, sans-serif]<?php echo base_url('/dashboard/fetch_single_data.$member['id'])?> but did not work. Kindly assist
<tbody>
                    <?php foreach ($users as $member) { ?>
                      <tr>
                        <td style="text-align: center;"><?php echo $member['id']; ?></td>
                        <td style="text-align: center;"><?php echo $member['title']; ?> <?php echo $member['surname']; ?> <?php echo $member['first_name']; ?> <?php echo $member['middle_name']; ?></td>
                        <td style="text-align: center;"><?php echo $member['work_place']; ?></td>
                        <td style="text-align: center;"><?php echo $member['email']; ?></td>
                        <td style="text-align: center;"><?php echo $member['member_num']; ?></td>
                        <td><a href="<?php echo base_url('/dashboard/fetch_single_data')?>" class = "btn btn-primary">Edit</a></td>
                        <td><a href="<?php echo base_url('/dashboard/fetch_single_data')?>" class = "btn btn-primary">Delete</a></td>
                      </tr>
                    <?php } ?>
                  </tbody>


RE: How do I echo datase id in base url? CI4? - demyr - 03-29-2021

On your edit page you will need the information of that specific user. User id, or using ids will always be the best option for you.

PHP Code:
<td><a href="<?php echo base_url('/dashboard/fetch_single_data').'/'.$member['id'];?>" class = "btn btn-primary">Edit</a></td>
<
td><a href="<?php echo base_url('/YourController/delete_single_user').'/'.$member['id'];?>" class = "btn btn-primary">Delete</a></td

Now on your url  for the edit page you will have the user id in one of the url segments.

In your controller:

PHP Code:
$user_id $this->request->uri->getSegment(2); // or 3 or 4 on which uri segment your id is 

then find the user details according to this id, and send them to the edit_user page as usual.