I'm trying to figure how to iterate through this table which shows monthly records provided by different facilities within any one month.
As it is, every record from each facility has a month associated with it, but I want to make it so that there only one month record, followed by the next month displaying in the same way and so on.
I've been told to use an if statement to iterate through the month column to determine the number of rows one month record should cover, but I'm confused regarding the syntax, any suggestions?
This is the table code I'm working with atm:
<table id="table2" class="table table-bordered table-striped table-condensed table-hover display" >
{{-- Beginning of headers --}}
<thead>
<tr class="text-center">
<th>Month</th>
<th>Grade</th>
<th colspan="3">Volume (m<sup>3</sup>)</th>
</tr>
<tr class="text-center">
<th></th>
<th></th>
<th>Received</th>
<th>Milled</th>
<th>Balance</th>
</tr>
</thead>
{{-- End of headers --}}
{{-- Beginning of data --}}
#foreach ($grades1 as $g)
<tbody class="text-center">
<tr class="text-center">
<td rowspan="100">{{$g->yr_mm}}</td>
<tr>
<td>{{$g->grade}}</td>
<td>{{$g->vol_received}}</td>
<td>{{$g->vol_milled}}</td>
<td>{{$g->vol_balance}}</td>
</tr>
</tr>
</tbody>
#endforeach
{{-- End of data --}}
</table>
Related
I have a api with a unique number, the number is different, so when i call api with this unique number, i get back data, i am showing data in table. the table has a column name "amount".
as its dynamic data coming from an api, i am just stucked how i can show total amount in the very bottom of the table. i am using laravel.
my code sample
<table class="table table-one">
<thead class="table-success">
<tr>
<th scope="col">Inst. No.</th>
<th scope="col">PR No.</th>
<th scope="col">PR Date</th>
<th scope="col">Prem. Amt.</th>
</tr>
</thead><!-- ends: thead -->
<tbody>
#foreach ($results['polinfo'] as $data)
#foreach ($data['poldata'] as $res)
<tr>
<th scope="row">{{$res['INSTALNO']}}</th>
<td>{{$res['PR_NO']}}</td>
<td>{{$res['PR_DATE']}}</td>
<td>{{$res['AMOUNT']}}</td>
</tr>
#endforeach
#endforeach
</tbody><!-- ends: tbody -->
</table>
i have to calcualte all {{$res['AMOUNT']}} and have to show it as total amount.
Thanks in advance.
If you need the value only after the foreach you can get away with a separate variable to which to add the amounts:
#php($amount = 0)
#foreach ($results['polinfo'] as $data)
#foreach ($data['poldata'] as $res)
<tr>
<th scope="row">{{$res['INSTALNO']}}</th>
<td>{{$res['PR_NO']}}</td>
<td>{{$res['PR_DATE']}}</td>
<td>{{$res['AMOUNT']}}</td>
</tr>
#php($amount += (int) $res['AMOUNT'])
#endforeach
#endforeach
Amount: {{ $amount }}
Please help check the code to see where there is error as I am not a coder but just using the application from another developer
<div class="bs-example widget-shadow table-responsive" data-example-id="hoverable-table">
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Client name</th>
<th>Amount</th>
<th>Payment mode</th>
<th>Receiver's email</th>
<th>Status</th>
<th>Date created</th>
<th>Option</th>
</tr>
</thead>
<tbody>
#foreach($withdrawals as $deposit)
<tr>
<th scope="row">{{$deposit->id}}</th>
<td>{{$deposit->duser->name}}</td>
<td>{{$deposit->amount}}</td>
<td>{{$deposit->payment_mode}}</td>
<td>{{$deposit->duser->email}}</td>
<td>{{$deposit->status}}</td>
<td>{{$deposit->created_at}}</td>
<td> <a class="btn btn-default" href="{{ url('dashboard/pwithdrawal') }}/{{$deposit->id}}">Process</a></td>
</tr>
#endforeach
The problem is in {{$deposit->duser->name}} and {$deposit->duser->email}}. Every withdrawal must have a valid user ID. This user ID will be matched against user table and the name and email of that user will be showed in blade.
What is happening is this, one or more $deposit has invalid user ID. So, the blade is trying to search in the table to get the name and email. But it is not finding it. So essentially it is trying to get the name value of a null object and crashing the app.
You can try to check if the duser have a null value by using following code,
#foreach($withdrawals as $deposit)
#if(!is_null($deposit->duser))
<tr>
<th scope="row">{{$deposit->id}}</th>
<td>{{$deposit->duser->name}}</td>
<td>{{$deposit->amount}}</td>
<td>{{$deposit->payment_mode}}</td>
<td>{{$deposit->duser->email}}</td>
<td>{{$deposit->status}}</td>
<td>{{$deposit->created_at}}</td>
<td> <a class="btn btn-default" href="{{ url('dashboard/pwithdrawal') }}/{{$deposit->id}}">Process</a></td>
</tr>
#endif
#endforeach
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 table display and each row contains a button. With this button l have to pass the id to the controller where using this Admin can view user details one by one.
<table id="example2" class="table table-bordered table-hover" style="text-align: center">
<thead>
<tr>
<th>Applicant ID</th>
<th>Full name</th>
<th>Position applied</th>
<th>Date & time applied</th>
<th>View CV</th>
</tr>
</thead>
<tbody>
#foreach ($jobapplied as $row)
<tr>
<td>{{$row->app_id}}</td>
<td>{{$row->fullname}}</td>
<td>{{$row->position}}</td>
<td>{{$row->created_at}}</td>
<td>
<button type="submit" class="btn btn-
default" name="viewcv"> View</button> <br>
<br>
</td>
</tr>
#endforeach
</tbody>
</table>
Please check the code , hope it helps:
<table id="example2" class="table table-bordered table-hover" style="text-align: center">
<thead>
<tr>
<th>Applicant ID</th>
<th>Full name</th>
<th>Position applied</th>
<th>Date & time applied</th>
<th>View CV</th>
</tr>
</thead>
<tbody>
#foreach ($jobapplied as $row)
<tr>
<td>{{$row->app_id}}</td>
<td>{{$row->fullname}}</td>
<td>{{$row->position}}</td>
<td>{{$row->created_at}}</td>
<td>CV</td>
</tr>
#endforeach
</tbody>
</table>
Assuming you want to pass the field "id" or change it according to your requirement.
If you want to link to a show view, try something like this:
#foreach ($jobapplied as $row)
<tr>
<td>{{$row->app_id}}</td>
<td>{{$row->fullname}}</td>
<td>{{$row->position}}</td>
<td>{{$row->created_at}}</td>
<td>
<a href="{{action('JobController#show', $row->id)}}" class="btn btn-default">View</button>
</td>
</tr>
#endforeach
This will create a link to a view, where you can show the data.
In your controller JobController, you must create a function that receives the data:
public function show(Request $request, $id) {
...
}
Just pass the id of the record to controller function and get the details from database.
<td>
View <br>
</td>
I've been hunting around, but all the answers and documentation on this is for tables that aren't dynamically generating everything.
This is my blade file:
#extends('layout')
#section('content')
<h1>User Profile Data</h1>
<table class="table table-striped">
<tr>
#foreach ($columns as $column => $name)
<th><strong> {{ $name }} </strong></th>
#endforeach
#foreach ($profile as $person)
#foreach ($person as $name)
<td> {{ $name }} </td>
#endforeach
#endforeach
</tr>
</table>
#stop
It's all working, except for one problem, the heads go horizontally, rather than vertically. I'd like to be able to automatically populate the data from the database and have it displayed side by side.
Like so:
Name: John
Age: 25
Height: 176
etc.
What am I missing?
v.1 Directly generate the vertical headers table.
This can be easily solved after you realize how your table will actually look like in HTML, in order to have vertical headers.
<h1>User Profile Data</h1>
<table class="table table-striped">
<tr>
<th><strong> Name: </strong></th>
<td> John </td>
<td> Joane </td>
</tr>
<tr>
<th><strong> Surname: </strong></th>
<td> Doe </td>
<td> Donald </td>
</tr>
<tr>
<th><strong> Email: </strong></th>
<td> john.doe#email.com </td>
<td> jane#email.com </td>
</tr>
</table>
After you know your above goal you just have to nest the foreach loops so that you can populate the data.
For each column you'll have to return the matching data from the profile.
Instead of returning $person->name use $person[$col]
To nest the foreach use the same technique for your other question:
How to show data from (multidimensional?) arrays with Laravel 5.3 blade
v.2 Use normal tables combined with CSS tricks to reflow table
Import twitter bootstrap and use .table-reflow on a well formed table.
The generated table will look like this and can be generated with your initial laravel code:
<table class="table table-striped table-hover table-reflow">
<thead>
<tr>
<th ><strong> Name: </strong></th>
<th ><strong> Surname: </strong></th>
<th ><strong> Email: </strong></th>
</tr>
</thead>
<tbody>
<tr>
<td> John </td>
<td> Doe </td>
<td> john.doe#email.com </td>
</tr>
<tr>
<td> Joane </td>
<td> Donald </td>
<td> jane#email.com </td>
</tr>
</tbody>
</table>
Content order and complex tables:
Beware that the table-reflow style changes the visual order of content. Make sure that you only apply this style to well-formed and simple data tables (and in particular, don’t use this for layout tables) with appropriate <th> table header cells for each row and column.
In addition, this class will not work correctly for tables with cells that span multiple rows or columns (using rowspan or colspan attributes).
You should check the docs here:
twitter-bootstrap .table-reflow
Edit:
In addition to Kronmark's excellent points, I'm leaving this here for new people. This is what the automated table might look like:
<table class="table table-striped table-hover table-reflow">
#foreach($array as $key=>$value)
<tr>
<th ><strong> {{ $key }}: </strong></th>
<td> {{ $value }} </td>
</tr>
#endforeach
</table>
The key is the title from the table, the value is the data point associated with it. I.e. Full_Name = Key, John Magsson = value.
This is produced from an array, the process should be explained here:
Blade view not printing data from array
Good luck. :)