I am trying to populate table with headers like this table .
And array returns this type of data.
I tried this but not works.
#foreach ($players['headers'] as $row_header)
<tr>
#foreach ($players['values'] as $values)
<th scope="row" class="col-3">{{ $row_header }}</th>
<th class="col-3">{{ $values['values'][0] }}</th>
<td class="col-3">{{ $values['values'][1] }}</td>
#endforeach
</tr>
#endforeach
Without knowing what error or inaccurate outcome you're currently seeing, it's hard to give you a definitive answer. My suggestion based on the images you provided would be to try something like this:
#foreach ($players['headers'] as $key => $row_header)
<tr>
<th scope="row" class="col-3">{{ $row_header }}</th>
#foreach ($players['values'] as $values)
<td class="col-3">{{ $values['values'][$key] }}</td>
#endforeach
</tr>
#endforeach
You don't need to output the $row_header foreach iteration of $players['values'], you only need to output it once.
Your setup doesn't take into account which iteration of the foreach you're on, so you're always outputting "matches" and "innings" even when you want to be outputting other values.
Related
I'm retrieving the JSON array from my DB and my array is:
{"Position":["first","second","third","fourth"],"Color":["Red",Blue,Pink,Teal]}
I want to show them in table inside a foreach loop
#foreach ($orderProduct->column as $item)
<thead>
<tr>
<th>{{ $item['Position'] }}</th>
<th>{{ $item['Color'] }}</th>
</tr>
</thead>
#endforeach
I want the output to be like this
<thead>
<tr>
<th>first</th>
<th>Red</th>
</tr>
</thead>
<thead>
<tr>
<th>second</th>
<th>Blue</th>
</tr>
</thead>
<thead>
<tr>
<th>third</th>
<th>Pink</th>
</tr>
</thead>
But it doesn't work.
Any ideas?
#for ($i = 0; $i < count($orderProduct->column['Position']); $i++)
<thead>
<tr>
<th>{{ $orderProduct->column['Position'][$i] }}</th>
<th>{{ $orderProduct->column['Color'][$i] }}</th>
</tr>
</thead>
#endfor
#foreach (array_combine($orderProduct['Position'], $orderProduct['Color']) as $position => $color)
<thead>
<tr>
<th>{{ $position }}</th>
<th>{{ $color }}</th>
</tr>
</thead>
#endforeach
Because you're using Laravel, I would suggest to make use of the Collection's zip method that "merges together the values of the given array with the values of the original collection at their corresponding index" (Docs)
You would use it like this:
$newArray = collect($array['Position'])->zip($array['Color']);
#foreach($newArray as [$position, $color])
{{ $position }}
{{ $color }}
#endforeach
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 }}
I have a problem with #foreach in my blade.php. When I insert movie with multiple categories my other moves to the right. Here is how it looks in browser
and here is code in blade
#if($movies)
<div class="row">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Categories</th>
<th>Actors</th>
</tr>
</thead>
<tbody>
#foreach($movies as $movie)
<tr>
<td>{{$movie->name}}</td>
#foreach($movie->categories as $category)
<td>{{$category->category_name}}</td>
#endforeach
#foreach($movie->actors as $actor)
<td>{{$actor->actor_name}}</td>
#endforeach
</tr>
#endforeach
</tbody>
</table>
#endif
Your issue lies here:
#foreach($movie->categories as $category)
<td>{{$category->category_name}}</td>
#endforeach
You are saying that for each category, it should insert a new <td> into you table. This will of course skew the content since your table expects a set number of columns.
Instead, you should move your foreach statement inside the <td></td>
<td>
#foreach($movie->categories as $category)
{{$category->category_name}}
#endforeach
</td>
This will print the links for each category in the same column.
Trying to make one html table where is showing what login users choose.
One login auth users and one form data.
Here data is showing on page but scramled in table.
Homedata is showing twice.
Here is my index page where im trying to do:
<table class="table" id="users-info">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>
<th scope="col">Naional Number</th>
<th scope="col">Device</th>
<th scope="col">Reimbursment</th>
<th scope="col">Warranty</th>
</tr>
</thead>
<tbody>
#if(count($users) > 0)
#foreach($users as $user)
<tr>
<th scope="row">{{ $user->id }}</th>
<td>{{ $user->firstname }}</td>
<td>{{ $user->lastname }}</td>
<td>{{ $user->phone }}
#foreach($homedata as $homedatas)
<td>{{$homedatas->device}}</td>
<td>{{$homedatas->reimburse_Pension}}</td>
<td>{{$homedatas->bonus_remainder}}</td>
#endforeach
</td>
</tr>
#endforeach
#endif
</tbody>
</table>
Please help.
if there is another way please feel free suggest.
Hey everyone who share the same problem.
I add in second foreach ->slice(0, 1) and that foreach just going once, that automaticaly means no duplicate data :)
I have a prices table that stores the date which a product cost was stored. There is a relationship between the product & price model which works very well by returning the collection. I want to display a table with a date & product name as the columns, then display the DISTINCT dates & the corresponding product cost on each row. Below is my blade view code and what the table looks like
view - code
<table class="table table-striped">
<thead>
<th>Date</th>
#if (isset($products) && !empty($products))
#foreach ($products as $product)
<th>{{ ucwords($product->name) }}</th>
</thead>
<tbody>
#foreach ($product->prices as $price)
<tr>
<td>{{ $price->date }}</td>
<td>{{ $price->cost }}</td>
</tr>
#endforeach
#endforeach
#else
Product price is not available
#endif
</tbody>
</table>
browser-view
Changing my code by ending the first foreach loop, gives me something close to what i want but only the cost for the last product is displayed
alternative code
<table class="table table-striped">
<thead>
<th>Date</th>
#if (isset($products) && !empty($products))
#foreach ($products as $product)
<th>{{ ucwords($product->name) }}</th>
#endforeach
</thead>
<tbody>
#foreach ($product->prices as $price)
<tr>
<td>{{ $price->date }}</td>
<td>{{ $price->cost }}</td>
</tr>
#endforeach
#else
Product price is not available
#endif
</tbody>
</table>
Browser-view
How do i display all of my product cost values for each date in the format of the last picture?