'how to pass row id in href of a tag in codeigniter controller?
I am using jqxgrid
in codeigniter
to display records from mysql
database
. while displaying the data, I made a column named 'action' that contains edit a
tag to redirect to another page for editing a specific record. I need to assign id to href
attribute in order to do that. but I can't correctly do that.
In controller, tax.php:
foreach($result as $row){
$data[$i]['tax_id']=$row['tax_id'];
$data[$i]['tax_name']=$row['tax_name'];
$data[$i]['action']='<a href="<?php echo base_url()?>/edit_tax/$row["tax_id"];">Edit</a>';
$i++;
}
how can i correctly assign tax_id to my url?
Solution 1:[1]
I believe you have to evaluate $row["tax_id"]
as a PHP expression:
$data[$i]['action']='<a href="<?php echo base_url()?>/edit_tax/<?php echo $row["tax_id"]; ?>">Edit</a>';
Edit: Use PHP's string concatenation to construct the <a>
element:
$data[$i]['action']='<a href="' . base_url() . '/edit_tax/' . $row["tax_id"] . '">Edit</a>';
Solution 2:[2]
This is how you do it.
<?php
foreach($result as $row)
{
$editurl = base_url() . 'admin/edit-user/' . $row['tax_id'];
?>
<a href="<?php echo $editurl; ?>" class="edit-user" >Edit</a>
<?php
}
?>
Do let me know if it didn't work.
Solution 3:[3]
Use below code:
$id = $row["tax_id"];
$data[$i]['action']='<a href="'.base_url().'/edit_tax/'.$id.'">Edit</a>';
It will work properly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Jaymin |
Solution 3 |