I'm trying to create DataTable in CodeIgniter with data from MySql. I'm not sure how to create form on DataTable that will handle checkboxes on each row.
HTML
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Price</th>
<th>Discount</th>
</tr>
</thead>
<tfoot>
<tr>
<th></th>
<th>Name</th>
<th>Price</th>
<th>Discount</th>
</tr>
</tfoot>
<tbody>
<?php foreach($data as $d): ?>
<tr>
<td></td>
<td><?=$d->name?></td>
<td><?=$d->price?></td>
<td><?=$d->discount?>%</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Related
I am trying to filter a dynamic table in Laravel 9 by variable "type" but I don't know the value of the type because it is inserted automatically by the user.
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>IdPp</th>
<th>Name</th>
<th>Type</th>
<th>Position</th>
</tr>
</thead>
<tbody>
#foreach($parts as $part)
<tr>
<th>{{$part->id}}</th>
<th>{{$part->Name}}</th>
<th>{{$part->type->intituléTypePP}}</th>
<th>{{$part->position->intituléPositionP}}</th>
</tr>
#endforeach
</tbody>
</table>
i have this code in my blade.php file
<table class="table table-success table-striped">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Username</th>
<th scope="col">Password</th>
<th scope="col">Email</th>
</tr>
<tbody>
#foreach($users as $user)
<tr>
<th scope="row">{{$user->ID}}</th>
<td>{{$user->username}}</td>
<td>{{$user->password}}</td>
<td>{{$user->email}}</td>
</tr>
#endforeach
</tbody>
</table>
and when i call my blade.php file to view a html page, i see only the emails from data.
This is the view when i run a dd($user) command.
This is a Html page
Looks like you got names wrong. Try this:
<table class="table table-success table-striped">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Username</th>
<th scope="col">Password</th>
<th scope="col">Email</th>
</tr>
<tbody>
<?php
foreach($users as $user){
echo "<tr>
<th scope='row'>".$user['ID']."</th>
<td>".$user['user_login']."</td>
<td>".$user['user_pass']."</td>
<td>".$user['user_email']."</td>
</tr>";}
?>
</tbody>
</table>
I am making a table which will fetch data from API. I am able to fetch the first value, How can i use foreach with my code? I am not able to do so.
My Table:
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Steam URL</th>
</tr>
</thead>
<tbody>
<tr>
<th><?php echo $name;?></th>
<th><?php echo $steam;?></th>
</tr>
</tbody>
</table>
And My PHP Code:
$name = $json->submissions[0]->data->name;
$steam = $json->submissions[0]->data->steam;
It's showing first value correct but not able to get the second entry.
Try this one if it works!
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Steam URL</th>
</tr>
</thead>
<tbody>
<?php foreach ($json->submissions as $key => $submission): ?>
<tr>
<th><?php echo $submission->data->name;?></th>
<th><?php echo $submission->data->steam;?></th>
</tr>
<?php endforeach ?>
</tbody>
</table>
Hello i am a laravel beginner , when i do foreach its shows double of all single items what should i do with it code and ss are below
Brower image
code
<div >
<h1 style="text-align: center">Lists of Outlets</h1>
#foreach($outlets as $outlet)
<table class="table table-striped">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
</tbody>
</table>
#endforeach
</div>
The issue is, you have put the entire table inside the loop, which is wrong. You have to only put the tr inside the loop.
Try this:
#foreach($outlets as $outlet)
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
#endforeach
and one more thing, you are also using the static content inside the loop instead of using the loop variable value. So instead of:
<td>john#example.com</td>
it is something like:
<td>{{ $outlet['name'] }}</td> <!-- where name is the index in outlet array -->
#foreach should be inside <tbody> and instead of hard-coded content, you should be using $outlet variable to get firstname, lastname and Email:
<div>
<h1 style="text-align: center">Lists of Outlets</h1>
<table class="table table-striped">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
#foreach($outlets as $outlet)
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
#endforeach
</tbody>
</table>
</div>
I have a requirement to output a table using Smarty and then have the user select a row to take them to another page.
I can display the table fine:
{html_table cols="Job Title,Salary,Sector,Location" loop=$results}
which gives:
<table border="1">
<thead>
<tr>
<th>Job Title</th>
<th>Salary</th>
<th>Sector</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dog walker</td>
<td>20000</td>
<td>None</td>
<td>London</td>
</tr>
<tr>
<td>F1 Driver</td>
<td>10000000</td>
<td>Financial Services</td>
<td>Scotland</td>
</tr>
</tbody>
</table>
but I am not sure if it is possible to add a hyperlink as an additional column to the table that links to a page using a hidden id.
So I would want something link this:
<table border="1">
<thead>
<tr>
<th>Job Title</th>
<th>Salary</th>
<th>Sector</th>
<th>Location</th>
<th>Apply</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dog walker</td>
<td>20000</td>
<td>None</td>
<td>London</td>
<td>Apply</td>
</tr>
<tr>
<td>F1 Driver</td>
<td>10000000</td>
<td>Financial Services</td>
<td>Scotland</td>
<td>Apply</td>
</tr>
</tbody>
</table>
Is that possible?
Yes, but you need to modify the $results array before you pass it to Smarty so that the 4th element of each row contains the link as a string. There's no way to have {html_table} generate the link for you.