How to get id of a CRUD element [Codeigniter]

Asked

Viewed 265 times

0

My question is this: I have a CRUD done in CodeIgniter, but the table rows are not in format localhost/crud/produtos/[:num].

In the last column of the table there are action buttons to edit and remove, one for each row. How can I get on controller the id of the line where the button is pressed?

Pus in a input guy Hidden id value, and obtained in controller by the way post. There is another more agile method to do?

<?php foreach($query as $row): ?>
    <tr>
        <th><?php echo $row->id; ?></th>
        <td><?php echo $row->autocarro; ?></td>
        <td><?php echo date("d-m-Y", strtotime($row->validade)); ?></td>
        <td>
            <form method="post" type="submit" action="<?php echo base_url('sistema/edit_extintores'); ?>" style="padding-right: 4px;"> 
                <input name="id_ext" type="hidden" value="<?php echo $row->id; ?>">
                <button type="submit"><i class="fa fa-pencil"></i></button>          
            </form>
            <form method="post" type="submit" action="<?php echo base_url('#'); ?>"> 
                <input name="id_ext" type="hidden" value="<?php echo $row->id; ?>">
                <button type="submit"><i class="fa fa-trash"></i></button>          
            </form>
        </td>
    </tr>
<?php endforeach; ?>

Imagem

The data is obtained from the BD table, and I want to click the button as indication 1 in the image, get the id of that line to get all the information respective to that id of the database.

  • Put some example code you are using...

  • updated the post

  • Dude I’ve been using Codeigniter for 2 years and I don’t understand your question. localhost/crud/products/[:num]. Have you done the route? Was it in the route settings? Another you want to display what kind of information pq Oce back in your post text goes nowhere what Oce wants you to do to edit seems ok but the trash doesn’t think Oce is wanting 2 different things Oce can make Edit go to one popup and remove it to another

  • garbage is not yet configured, I just wanted a way to get the information line id, without having to use that input type Hidden gambiarra

  • Of course there are ways, you can use some forms. Using GET method instead of Post, you can use Jquery, it only depends on what you want exactly, why in your question you have already solved.

1 answer

-1

Use the $row['id']

While you’re inside your block foreach you can take this data.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.