I want to display subcategory in td but I like the result with some formatting. The output is going on weight column so need help to improve code. How can I display one by one product_name? for each loop create the second td & it will go to the weigh column. I want to display this product_name with auto-increment $i
Excepted result:
product_name
1)face wash
2)face cream
my result:
face wash face cream
Blade file code:
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><strong>Order summary</strong></h3>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-condensed">
<thead>
<tr>
<td><strong>Product Name</strong></td>
<td class="text-center"><strong>Weight</strong></td>
<td class="text-center"><strong>Quantity</strong></td>
<td class="text-right"><strong>Price</strong></td>
<td class="text-right"><strong>SubTotal</strong></td>
</tr>
</thead>
<tbody>
<!-- foreach ($order->lineItems as $line) or some such thing here -->
<tr>
<?php
$subcategory=explode(',', $bill->name_of_subcategory);
$weight=explode(',', $bill->weight);
$orders_qty=explode(',', $bill->orders_qty);
$price=explode(',', $bill->price);
$orders_subtotal=explode(',', $bill->orders_subtotal);
?>
<td><?php
$subcategory=explode(',', $bill->name_of_subcategory);
for($i=0;$i<count($subcategory);$i++)
{
echo $subcategory[$i];
}
?></td>
<td class="text-center">{{ $bill->weight }}</td>
<td class="text-center">{{ $bill->orders_qty }}</td>
<td class="text-center">{{ $bill->price }}</td>
<td class="text-center">{{ $bill->orders_subtotal }}</td>
</tr>
<tr>
<td class="thick-line"></td>
<td class="thick-line"></td>
<td class="thick-line"></td>
<td class="thick-line text-center"><strong>Subtotal</strong></td>
<td class="thick-line text-right">{{ $bill->total }}</td>
</tr>
<tr>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line text-center"><strong>SGST</strong></td>
<td class="no-line text-right">{{ $bill->sgst }}%</td>
</tr>
<tr>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line text-center"><strong>CGST</strong></td>
<td class="no-line text-right">{{ $bill->cgst }}%</td>
</tr>
<tr>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line text-center"><strong>IGST</strong></td>
<td class="no-line text-right">{{ $bill->igst }}%</td>
</tr>
<tr>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line"></td>
<td class="no-line text-center"><strong>Total</strong></td>
<td class="no-line text-right">{{ $bill->grand_total }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
Try this
<table>
<tr>
<?php
$subcategory=explode(',', $bill->name_of_subcategory);
foreach($subcategory as $row){ ?>
<td>{{$row}}</td>
<?php } ?>
</tr>
</table>
you should create a <td> foreach result.
<table>
<?php
$subcategory=explode(',', $bill->name_of_subcategory);
for($i=0;$i<count($subcategory);$i++)
{
echo "<tr><td>".$subcategory[$i]."</td></tr>";
}
?>
</table>
Related
I am working with DOMPDF in Laravel 8, when I create a table with many records and jumps to the next page, it does not perform the page break as it should, Could someone help me to know what I am doing wrong?. I was reading many articles on the internet and none of them worked for me.
Here is my code:
<div class="box-products-table">
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td class="text-center roboto">{{ trans('image') }}</td>
<td class="text-center roboto">{{ trans('just_name') }}</td>
<td class="text-center roboto">{{ trans('quantity') }}</td>
<td class="text-center roboto">{{ trans('unit_price') }}</td>
<td class="text-center roboto">{{ trans('taxes') }}</td>
<td class="text-center roboto">{{ trans('subtotal') }}</td>
<td class="text-center roboto">{{ trans('total_price') }}</td>
</tr>
#for($i = 0; $i < 100; $i++)
<tr>
<td class="text-center"><img src="{{ public_path('storage/uploads/products/d6d74f351d482bb41787e86350ace02e.jpg') }}" height="70px"></td>
<td class="text-center">PORTATIL DELL 4HWRT</td>
<td class="text-right">526</td>
<td class="text-right">$ 4.985.650</td>
<td class="text-right">$ 947.273,5</td>
<td class="text-right">$ 99.713.000</td>
<td class="text-right">$ 2.622.451.900</td>
</tr>
#endfor
</tbody>
</table>
</div>
Result:
Go to screenshot (https://ibb.co/Rj5ZPTW)
.page_break {
page-break-before: always;
}
<!-- adjust $n as needed. $n = number of rows that fit in a page -->
#foreach(collect(range(1,100))->chunk($n) as $chunk)
<div class="box-products-table">
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td class="text-center roboto">{{ trans('image') }}</td>
<td class="text-center roboto">{{ trans('just_name') }}</td>
<td class="text-center roboto">{{ trans('quantity') }}</td>
<td class="text-center roboto">{{ trans('unit_price') }}</td>
<td class="text-center roboto">{{ trans('taxes') }}</td>
<td class="text-center roboto">{{ trans('subtotal') }}</td>
<td class="text-center roboto">{{ trans('total_price') }}</td>
</tr>
#foreach($chunk as $i)
<tr>
<td class="text-center"><img src="{{ public_path('storage/uploads/products/d6d74f351d482bb41787e86350ace02e.jpg') }}" height="70px"></td>
<td class="text-center">PORTATIL DELL 4HWRT</td>
<td class="text-right">526</td>
<td class="text-right">$ 4.985.650</td>
<td class="text-right">$ 947.273,5</td>
<td class="text-right">$ 99.713.000</td>
<td class="text-right">$ 2.622.451.900</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<div class="page-break"></div> <!-- break page -->
#endforeach
I tried to do it but the big problem is foreach here i have the foto:
Problem
Here is my table picture
Here is the code but still have problem:
<div class="row">
<table class="table table-bordered table-striped table-highlight">
<tbody>
<tr height="100">
<td rowspan="6" height="120" width="3%" style="vertical-align: middle;">
<p style="white-space: nowrap;writing-mode: vertical-lr;transform: rotate(180deg);font-weight: bold;"><font >Here is my title </font></p>
</td>
<td colspan="3">
<font>Name</font>
</td>
<td width="64">
<font>Article</font>
</td>
<td width="64">
<font>Price</font>
</td>
<td width="64">
<font>Date</font>
</td>
</tr>
<tr height="20">
<td colspan="3" rowspan="5" height="120" ></td>
<td rowspan="5" style="vertical-align: top;"></td>
<td rowspan="5" style="vertical-align: top;"></td>
<td rowspan="5" style="vertical-align: top;"></td>
</tr>
<tr height="15">
</tr>
<tr height="15">
</tr>
<tr height="15">
</tr>
<tr height="15">
</tr>
</tbody>
</table>
</div>
How can i do it so that when i use foreach it will insert new td and the vertical Here is my title will be there?
ok, so you're using php here's a very basic example on how you can do that, i'm assuming you already did query and the fetching part, and this is a guess of your data structure, you can adjust it to your liking :
<div class="row">
<table class="table table-bordered table-striped table-highlight">
<tbody>
<tr height="100">
<td rowspan="100%" height="120" width="3%" style="vertical-align: middle;">
<p style="white-space: nowrap;writing-mode: vertical-lr;transform: rotate(180deg);font-weight: bold;"><font >Here is my title </font></p>
</td>
<td colspan="3">
<font>Name</font>
</td>
<td width="64">
<font>Article</font>
</td>
<td width="64">
<font>Price</font>
</td>
<td width="64">
<font>Date</font>
</td>
</tr>
<?php
foreach($data as $key => $value){
echo '<tr height="20">';
echo '<td colspan="3">'.$value['name'].'</td>';
echo '<td width="64" style="vertical-align: top;">'.$value['article'].'</td>';
echo '<td width="64" style="vertical-align: top;">'.$value['price'].'</td>';
echo '<td width="64" style="vertical-align: top;">'.$value['date'].'</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
here's a fiddle : https://jsfiddle.net/kkpjx328/
I hope this helps .
PS : on your next question, please consider adding the data structure and if possible, an example or code sample of what you've tried so far so we can provide more specific answers
How to get data and set in to php var when use file_get_contents PHP ?
this is code for http://www.example.com/test.php
<table align="center">
<thead style="background-color: #F0F0F0; color: #333333; text-align: center;">
<tr>
<th class="countryHeader">Country</th>
<th class="intHeader"> </th>
<th colspan="2" class="intHeader">Desktop CPM</th>
<th colspan="2" class="bannerHeader">Mobile CPM</th>
</tr>
</thead>
<tbody>
<tr class="breaker">
<td> </td>
<td>Highest</td>
<td>Unique</td>
<td>Raw</td>
<td>Unique</td>
<td>Raw</td>
</tr>
<tr class="odd rateVals">
<td class="countryName">United States</td>
<td class="cpmRaw">$2.00</td>
<td class="cpm">$3.44</td>
<td class="cpmRaw">$2.00</td>
<td class="cpmMobile">$1.63</td>
<td class="cpmMobileRaw">$0.97</td>
</tr>
<tr class="even rateVals">
<td class="countryName">Canada</td>
<td class="cpmRaw">$1.20</td>
<td class="cpm">$2.52</td>
<td class="cpmRaw">$1.20</td>
<td class="cpmMobile">$1.88</td>
<td class="cpmMobileRaw">$1.06</td>
</tr>
<tr class="odd rateVals">
<td class="countryName">United Kingdom</td>
<td class="cpmRaw">$1.60</td>
<td class="cpm">$2.10</td>
<td class="cpmRaw">$1.08</td>
<td class="cpmMobile">$1.71</td>
<td class="cpmMobileRaw">$0.94</td>
</tr>
<tr class="even rateVals">
<td class="countryName">Australia</td>
<td class="cpmRaw">$1.50</td>
<td class="cpm">$2.62</td>
<td class="cpmRaw">$1.20</td>
<td class="cpmMobile">$2.73</td>
<td class="cpmMobileRaw">$1.49</td>
</tr>
<tr class="breaker">
<td colspan="6"> </td>
</tr>
<tr class="odd rateVals">
<td class="countryName">United Arab Emirates</td>
<td class="cpmRaw">$1.48</td>
<td class="cpm">$2.49</td>
<td class="cpmRaw">$1.45</td>
<td class="cpmMobile">$2.11</td>
<td class="cpmMobileRaw">$1.42</td>
</tr>
<tr class="odd rateVals">
<td>All other countries</td>
<td>-</td>
<td colspan="2">$0.25 - $2.00</td>
<td colspan="2">$0.06 - $0.22</td>
</tr>
</tbody>
</table>
And this is code for my_code.php
<?php
$test = file_get_contents('http://www.example.com/test.php');
//echo $test;
?>
And i want to get php var from column Mobile CPM raw value like this
$United_States = "0.97";
$Canada = "1.07";
$United_Kingdom = "0.94";
$Australia = "1.49";
$United_Arab_Emirates = "1.42";
How can i do ?
If you want to parse a HTML document you should use PHP's DOMDocument. Instead of file_get_contents() you should use loadHTMLFile(). Because you are using CSS-classes you should view this post on how to find elements via class.
I'm using Laravel to create a PDF report that has a big table which has 3 other tables nested inside for the sake of side-by-side viewing. I know domPDF won't support Floating so I had to do this. I couldn't also use Positioning since there will be repeatations of the same element on page so this seemed like the best idea.
However, whenever I have multiple nested tables in PDF, this weird thing happens:
I have been able to find any solutions to this online.
Source Code:
#foreach ($employees as $employee)
<table style="width: 100%; margin-top: 5px; border-bottom: 1px solid grey; margin-bottom: 5px;" border="0" cellspacing="0" cellpadding="5">
<tbody>
<tr>
<td width="25%" style="background: lightgrey;">Name: <strong>{{$employee['info']->name}}</strong></td>
<td width="25%" style="background: lightgrey;">Mobile: <strong>{{$employee['info']->mobile}}</strong></td>
<td width="25%">Date: <strong>{{$inputs['date']}}</strong></td>
<td width="25%">Remarks:</td>
</tr>
<tr>
<td colspan="2">
<table style="width: 100%;" border="1" cellpadding="5" cellspacing="0">
<thead>
<tr>
<th colspan="3">Receive</th>
</tr>
</thead>
<tbody>
#if ($employee['given']->isEmpty())
<tr>
<td colspan="2"></td>
</tr>
#else
#foreach ($employee['given'] as $tr)
<tr>
<td>{{ strtoupper($tr->category) }}</td>
<td style="text-align: right;">{{ App\Transaction::formatMoney($tr->amount) }}</td>
</tr>
#endforeach
#endif
</tbody>
</table>
</td>
<td colspan="2">
<table style="width: 100%;" border="1" cellpadding="5" cellspacing="0">
<thead>
<tr>
<th colspan="3">Return</th>
</tr>
</thead>
<tbody>
#if ($employee['returned']->isEmpty())
<tr>
<td colspan="2"></td>
</tr>
#else
#foreach ($employee['returned'] as $tr)
<tr>
<td>{{ strtoupper($tr->category) }}</td>
<td style="text-align: right;">{{ App\Transaction::formatMoney($tr->amount) }}</td>
</tr>
#endforeach
#endif
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table style="width:100%" border="1" cellpadding="2" cellspacing="0">
<tbody>
<tr>
<td>Total Receive</td>
<td style="text-align: right;">{{ App\Transaction::formatMoney($employee['given']->sum('amount')) }}</td>
</tr>
<tr>
<td>Total Return</td>
<td style="text-align: right;">{{ App\Transaction::formatMoney($employee['returned']->sum('amount')) }}</td>
</tr>
<tr style="background-color: {{ $employee['returned']->sum('amount') - $employee['given']->sum('amount') < 0 ? 'lightgrey' : '' }}">
<td>Balance</td>
<td style="text-align: right;">{{ App\Transaction::formatMoney($employee['returned']->sum('amount') - $employee['given']->sum('amount')) }}</td>
</tr>
<tr>
<td>B2B</td>
<td style="text-align: right;">{{ App\Transaction::formatMoney($employee['b2b']) }}</td>
</tr>
<tr>
<td>Sale</td>
<td style="text-align: right;">{{ App\Transaction::formatMoney($employee['sale']) }}</td>
</tr>
</tbody>
</table>
</td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
#endforeach
It looks like your table headers ("Receive" and "Return") are set to colspan="3" while the actual number of columns in that table are only 2. It's obviously some buggy behavior around rendering the table, but if you set the colspan to 2 it should render as expected.
So, I have this PHP scraper code and HTML below that I want to scrape using Xpath.
When I try to scrape every #href, it shows outerHTML 14, when it is supposes to be 14
The #href is cut in half where the space are. What causes this?
$content = $xpath->query('//a');
foreach($content as $c){
var_dump(htmlspecialchars($c->C14N())); echo '<br>';
}
The one above is the CURL code.
Here is the HTML.
<div class="outercalendar" id="maincalendar821"><table class="calendarHeader">
<tbody><tr>
<td><input type="button" onclick="AjxGetMainCalendarMonth('2', '2015', '821')" value="<"></td>
<td class="calendarHeader" colspan="5">March 2015</td>
<td><input type="button" onclick="AjxGetMainCalendarMonth('4', '2015', '821')" value=">"></td>
</tr>
</tbody></table>
<table class="calendar">
<tbody><tr>
<td class="calendarDay">S</td>
<td class="calendarDay">M</td>
<td class="calendarDay">T</td>
<td class="calendarDay">W</td>
<td class="calendarDay">T</td>
<td class="calendarDay">F</td>
<td class="calendarDay">S</td>
</tr>
<tr>
<td class="calendar">1</td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar">7</td>
</tr>
<tr>
<td class="calendar">8</td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar">14</td>
</tr>
<tr>
<td class="calendar">15</td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar">21</td>
</tr>
<tr>
<td class="calendar">22</td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar">28</td>
</tr>
<tr>
<td class="calendar">29</td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
</tr>
</tbody></table>
</div>
The issue could be in the structure of the info stored in the tag.
I would suggest starting with a more detailed xpath:
//a/#href
so your initial code would be:
$content = $xpath->query('//a/#href');