How to skip row number for particular row in php? - php

Here is the piece of the code, in which the counter variable is used to add the question number automatically. I want to skip the question number if the type==4(last category) which is the question heading.
#php
$counter=0;
#endphp
#foreach($questions as $question)
<tr>
<td>{{++$counter}}</td>
<td colspan=4 style="text-align:left;">{{$question->title}}</td>
</tr>
<tr>
#if($question->type==1)
#include('partials.response',['question_no'=>$question->id,'question_title'=>$question->title])
#elseif($question->type==2)
#include('partials.attendance')
#elseif($question->type==3)
#include('par`enter code here`tials.rank')
#elseif($question->type==4)
#include('partials.question-heading')
#endif
</tr>
#endforeach

Related

populate table with headers using foreach loop in Laravel

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.

mPDF - Table Footer (tfoot) only appear on last page

im trying to add table footer(<tfoot></tfoot>) using mPDF to every bottom page (last row).
but it only appear on the last page. I have repeated but not . Example code below :
View
<table>
<th>Name</th>
<th>Position</th>
<tbody>
#foreach($datas as $data)
<tr>
<td> $data->name </td>
<td> $data->position</td>
</tr>
#endforeach
</tbody>
//i want to this to be on every page
<tfoot> Footer </foot>
</table>
Controller
$htmlString = \View::make('test_pdf',['datas'=>$datas]);
$htmlString = $htmlString->render();
$mpdf->SetFooter('Report_Name' | |{PAGENO}');
$mpdf->WriteHTML($htmlString);
return $mpdf->Output('test'.pdf','D');
Thank you in advanced!

Styling table in Laravel

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.

Laravel DomPDF error row not found

Am getting this error while generating pdf using DOMPDF
The row #2 could not be found, please file an issue in the tracker wit
I can view the output as html in my view page.But PDF is not generating am getting the above error.I have two arrays for the table headings and the results. MY code as follows:
My code:
<table width="100%" class="fullwidth border">
<thead>
<tr>
<th width="10%"></th>
<th width="10%"></th>
#foreach($selected_fields_top as $key => $value)
<th>{{ $value }}</th>
#endforeach
</tr>
</thead>
<tbody>
<table >
<tbody>
#foreach($selected_fields_left as $key => $value)
<tr><td><b>{{ $value }}</b></td>
<!-- <td> -->
#foreach($resultListLeft as $left_key => $valueArr)
#foreach($valueArr as $k => $v)
#if($v)
<table>
<tbody>
<!-- <tr> -->
#if($valueArr[$value])
<td width="10%">{{$valueArr[$value]}}</td>
#else
<td width="10%">Data not available</td>
#endif
#foreach($resultListTop as $key => $TopvalueArr)
#if($key==$left_key)
#foreach($TopvalueArr as $top_key => $top_value)
#if($top_value)
<td width="10%">{{$top_value}}</td>
#else
<td width="10%">Data not available</td>
#endif
#endforeach
#endif
#endforeach
<!-- </tr> -->
</tbody>
</table>
#endif
#endforeach
#endforeach
<!-- </td> -->
#endforeach
</tr>
</tbody>
</table>
i want to print the output like:-
Top heading1 Topheading2
Left heading 1 Left value Top value Top value
Left value Top value Top value
Left value Top value Top value
etc... etc... etc...
Left heading 2 Left value Top value Top value
Left value Top value Top value
Left value Top value Top value
etc... etc... etc...
First you have to var_dump the variable if they do contain such row.

Create HTML table with headers in a vertical column dynamically with laravel?

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. :)

Categories