Tournament table [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am trying to create a tournament table using PHP.
This is the HTML code sample.
<table>
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>final</th>
<th>winner</th>
</tr>
</thead>
<tbody>
<tr>
<td class="team">team1</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td class="team">team1</td>
<td></td>
<td></td>
</tr>
<tr>
<td class="team">team2</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="team">team4</td>
<td></td>
</tr>
<tr>
<td class="team">team3</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td class="team">team4</td>
<td></td>
<td></td>
</tr>
<tr>
<td class="team">team4</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td class="team">team4 vinner</td>
</tr>
<tr>
<td class="team">team5</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td class="team">team6</td>
<td></td>
<td></td>
</tr>
<tr>
<td class="team">team6</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td class="team">team8</td>
<td></td>
</tr>
<tr>
<td class="team">team7</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td class="team">team8</td>
<td></td>
<td></td>
</tr>
<tr>
<td class="team">team8</td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
I tried creating that table using for loops, but that didn't work very well.
Maybe you can give some hints? I am out of ideas.

The elimination system you are working with is called "single elimination" (sometimes "head to head") and the output you wish to achieve is often called "brackets".
Have a look at:
Generate a single elimination tournament
and: PHP Single Elimination Tournament Table
This one can be helpful too: Tournament bracket placement algorithm

Related

Codeigniter/CSS PDF Printout Align PDF Position

Problem: Currently I have problem aligning the PDF that I am creating as it is different with normal CSS that I know.
Problem:
What I need it to be solve:
Make it align, for the image I provided, I wanted "No.SAG" below "Old"
This is the code:
<table class="unstyledTable">
<thead>
<tr>
<th>Name:</th>
<th>Test Data</th>
<th></th>
<th>Number card IC</th>
<th></th>
<th></th>
</tr>
</thead>
<tfoot>
<tr>
<td>Name Agent::</td>
<td>TomHansom </td>
<td></td>
<td>New:</td>
<td>foot5</td>
<td></td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Address:</td>
<td>werwrwrwwwwwwwwwwwwww wwwwwwwwwwwwwwwwwwww</td>
<td></td>
<td>Old:</td>
<td>cell5_1</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td>No.SAG:</td>
<td>cell5_2</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td>Number.Siri:</td>
<td>cell5_3</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
Might be easier to put both in columns as tables in a parent table. Check out my code below to see if this is what you were after.
<table class="unstyledTable">
<tbody>
<tr>
<td valign="top"><table>
<tbody>
<tr class="unstyledTable">
<th>Name:</th>
<th>Test Data</th>
</tr>
<tr class="unstyledTable">
<td>Address:</td>
<td>werwrwrwwwwwwwwwwwwww wwwwwwwwwwwwwwwwwwww</td>
</tr>
<tr class="unstyledTable">
<td></td>
<td></td>
</tr>
<tr class="unstyledTable">
<td></td>
<td></td>
</tr>
<tr class="unstyledTable">
<td></td>
<td></td>
</tr>
<tr class="unstyledTable">
<td>Name Agent::</td>
<td>TomHansom </td>
</tr>
</tbody>
</table></td>
<td valign="top"><table>
<tbody>
<tr class="unstyledTable">
<th>Number card IC</th>
<th></th>
</tr>
<tr class="unstyledTable">
<td>Old:</td>
<td>cell5_1</td>
</tr>
<tr class="unstyledTable">
<td>No.SAG:</td>
<td>cell5_2</td>
</tr>
<tr class="unstyledTable">
<td>Number.Siri:</td>
<td>cell5_3</td>
</tr>
<tr class="unstyledTable">
<td></td>
<td></td>
</tr>
<tr class="unstyledTable">
<td>New:</td>
<td>foot5</td>
</tr>
</tbody>
</table></td>
</tr>
</tbody>
</table>

Automatically New Pages Created in HTML2PDF

I am using HTml2pdf library to convert HTML to PDF.
Below is the code i am using.
PHP
require __DIR__.'/vendor/autoload.php';
use Spipu\Html2Pdf\Html2Pdf;
$html2pdf = new Html2Pdf();
$html2pdf = new HTML2PDF('P', 'A4', 'en');
$html2pdf->setTestTdInOnePage(false);
$html = file_get_contents('index.html');
$html2pdf->writeHTML($html);
$html2pdf->output();
HTML
<div class="bap">
<div class="row">
<div class="par_col">
<div class="column">
<img src="b.jpg" alt="test">
<table style="width:99%" class="feetop">
<tr>
<td class="t_head">Challan No.</td>
<td class="lii undl">18584</td>
<td class="t_heada">Due Date:</td>
<td class="liia undl"></td>
</tr>
<tr>
<td class="t_head_c">Name</td>
<td colspan="3" class="lii undl">Hamza Zafeer</td>
</tr>
<tr>
<td>Program:</td>
<td class="lii undl de">BS Civil Tech </td>
<td >Roll No.</td>
<td class="undl"></td>
</tr>
<tr>
<td>Semester</td>
<td class="undl"></td>
<td>Session</td>
<td class="undl">2018-2021</td>
</tr>
</table>
<table style="width:99%" class="fee">
<tr>
<th >PARTICULARS</th>
<th>Rs.</th>
<th>Ps.</th>
</tr>
<tr>
<td>Registration Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Admission Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Tuition Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Laboratory Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Library Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Transcript / Degree Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Examination Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Security Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Hostel Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Transport charges</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Fine</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Misc.</td>
<td>1000</td>
<td></td>
</tr>
<tr>
<td>Total Payable</td>
<td>1000</td>
<td></td>
</tr>
</table>
<div class="btm">
<div class="fm rss"><strong>Rs. in words :</strong> One thousand only</div>
<div class="fm bt"> Cashier</div>
</div>
</div></div>
<div class="par_col">
<div class="column">
<img src="a.jpg" alt="test">
<table style="width:99%" class="feetop">
<tr>
<td class="t_head">Challan No.</td>
<td class="lii undl">18584</td>
<td class="t_heada">Due Date:</td>
<td class="liia undl"></td>
</tr>
<tr>
<td class="t_head_c">Name</td>
<td colspan="3" class="lii undl">Hamza Zafeer</td>
</tr>
<tr>
<td>Program:</td>
<td class="lii undl de">BS Civil Tech </td>
<td >Roll No.</td>
<td class="undl"></td>
</tr>
<tr>
<td>Semester</td>
<td class="undl"></td>
<td>Session</td>
<td class="undl">2018-2021</td>
</tr>
</table>
<table style="width:99%" class="fee">
<tr>
<th >PARTICULARS</th>
<th>Rs.</th>
<th>Ps.</th>
</tr>
<tr>
<td>Registration Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Admission Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Tuition Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Laboratory Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Library Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Transcript / Degree Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Examination Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Security Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Hostel Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Transport charges</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Fine</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Misc.</td>
<td>1000</td>
<td></td>
</tr>
</table>
<div class="btm">
<div class="fm rss"><strong>Rs. in words :</strong> One thousand only</div>
<div class="fm bt"> Cashier</div>
</div>
</div></div>
<div class="par_col">
<div class="column">
<img src="s.jpg" alt="test">
<table style="width:99%" class="feetop">
<tr>
<td class="t_head">Challan No.</td>
<td class="lii undl">18584</td>
<td class="t_heada">Due Date:</td>
<td class="liia undl"></td>
</tr>
<tr>
<td class="t_head_c">Name</td>
<td colspan="3" class="lii undl">Hamza Zafeer</td>
</tr>
<tr>
<td>Program:</td>
<td class="lii undl de">BS Civil Tech </td>
<td >Roll No.</td>
<td class="undl"></td>
</tr>
<tr>
<td>Semester</td>
<td class="undl"></td>
<td>Session</td>
<td class="undl">2018-2021</td>
</tr>
</table>
<table style="width:99%" class="fee">
<tr>
<th >PARTICULARS</th>
<th>Rs.</th>
<th>Ps.</th>
</tr>
<tr>
<td>Registration Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Admission Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Tuition Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Laboratory Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Library Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Transcript / Degree Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Examination Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Security Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Hostel Fee</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Transport charges</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Fine</td>
<td></td>
<td></td>
</tr>
<tr>
<td>Misc.</td>
<td>1000</td>
<td></td>
</tr>
</table>
<div class="btm">
<div class="fm rss"><strong>Rs. in words :</strong> One thousand only</div>
<div class="fm bt"> Cashier</div>
</div>
</div></div>
OUTPUT of HTML
But When i generate PDF, each section converted into a single page, and final PDF consisted on 3 pages.
Problem
It should not generate the 3 pages of PDF. Anybody can tell me what i am doing wrong, why it is creates 3 pages instead of 1 page?
I think it lacks the space, try to wrap your tables in one more table, like:
<table>
<tr>
<td>%table1HTML%</td>
</tr>
<tr>
<td>%table2HTML%</td>
</tr>
<tr>
<td>%table3HTML%</td>
</tr>
</table>

How to add data into HTML table irrespective of number of elements in array

I am trying to display the array data into HTML table but table design or structure should be untouched irrespective of number of elements in array.
I tried some of logic like looping, but table structure changes.I don't want that.
Here is my code:
<?php
$goods=["ABC","XYZ","PQR","DEF"];
$qty=[12345,25120,14521,12541];
$rate=[12.00,13.02,15.00,14.00];
?>
<table>
<tr>
<th>Sr No.</th>
<th>Goods Description</th>
<th>Total Quantity(pcs)</th>
<th>Rate per unit(Rs.)</th>
<th colspan="3">Amount</th>
</tr>
<?php
for($i=0;$i<count($goods);$i++) {
?>
<tr>
<td><?php echo $goods[$i];?></td>
<td><?php echo $qty[$i];?></td>
<td><?php echo $rate[$i];?></td>
</tr>
<?php } ?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Total Value</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Frieght</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Total Taxable Value</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Tax</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>tax</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>tax</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Total Tax Amount</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>Grand Total Tax Amount</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>ABC</td>
<td></td>
<td></td>
</tr>
</table>
Expected Output:
Expected_output
I think this is what you need. You had not included the words in the loop.
It was insanely hard to write this code on the phone so there may be something left out.
$goods=["ABC","XYZ","PQR","DEF"];
$qty=[12345,25120,14521,12541];
$rate=[12.00,13.02,15.00,14.00];
$words=["Total Value", "Frieght", "Total Taxable Value", "Tax", "Tax", "Tax", "Total Tax Amount"];
?>
<table>
<tr>
<th>Sr No.</th>
<th>Goods Description</th>
<th>Total Quantity(pcs)</th>
<th>Rate per unit(Rs.)</th>
<th colspan="3">Amount</th>
</tr>
<?php
for ($i=0;$i<count($words);$i++) {
?>
<tr>
<td><?php echo $i+1 . "."; ?></td>
<td><?php if(isset($goods[$i])) echo $goods[$i];?></td>
<td><?php if(isset($qty[$i])) echo $qty[$i];?></td>
<td><?php if(isset($rate[$i])) echo $rate[$i];?></td>
<td><?php echo $words[$i];?></td>
</tr>
<?php } ?>
</table>
https://3v4l.org/f1BnW.
Edit forgot number on first column.

mdpf can't create pdf with <b> or <s> tags

I'm trying to create a pdf out of an html table which is created through php.
I use php version 5.4.7 and mdpf version 5.7.3.
This code does not work:
<?php
include('../../mpdf/mpdf.php');
$mpdf=new mPDF('utf-8', 'A4-L');
$test2 = "<table class='timon' border='1'>
<thead>
<tr>
<th></th>
<th>Montag</th>
<th>Dienstag</th>
<th>Mittwoch</th>
<th>Donnerstag</th>
<th>Freitag</th>
<th>Avg. Tag</th>
</tr>
</thead>
<tbody>
<tr>
<td>Morgen (0.3) </td>
<td><s>test user 0.36</s><br /></td>
<td></td>
<td><s>test user 0.26</s><br /></td>
<td></td>
<td></td>
<td> </td>
</tr>
<tr>
<td>Mittag (0.5) </td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td> </td>
</tr>
<tr>
<td>Nachmittag (0.5) </td>
<td><s>test user 0.16</s><br /></td>
<td></td>
<td></td>
<td></td>
<td><s>test user 0.46</s><br /></td>
<td> </td>
</tr>
<tr>
<td>Ganzer Tag (1) </td>
<td></td>
<td></td>
<td><s>test user 1.2</s><br /></td>
<td></td>
<td></td>
<td> </td>
</tr>
<tr>
<td>Total Auslastung</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>Total Gruppe</td>
<td>7.5</td>
<td>7.5</td>
<td>7.5</td>
<td>7.5</td>
<td>7.5</td>
<td>7.5</td>
</tr><tr>
<td>Freie Plätze</td>
<td style='background-color:#c6efce;'>7.5</td>
<td style='background-color:#c6efce;'>7.5</td>
<td style='background-color:#c6efce;'>7.5</td>
<td style='background-color:#c6efce;'>7.5</td>
<td style='background-color:#c6efce;'>7.5</td>
<td style='background-color:#c6efce;'>7.5</td>
</tr>
</tbody>
</table>";
$mpdf->WriteHTML($test2,2);
$filename = "test.pdf";
$mpdf->Output($filename,'I');
exit;
?>
If I remove just one of the < s> tags, the PDF will be created fine. Eg.:
<td><s>test user 0.36</s><br /></td>
<td>test user 0.36<br /></td>
it also have problems with the < b> and < u> tag.
Any ideas?
You must close the <s> tag. mPDF is very strict with opening and closing tags. And not all of your opening tags are closed.
f.i.
<td><s>test user 0.36<s><br /></td>
Is not closed properly.
I found the mistake. I had an additional php include and this php had an body and html tag in it. I just removed it and now it works fine. BR

Parsing a complicated HTML table with PHP

I successfully parsed a dynamic table with the following PHP code:
$docH = new DOMDocument();
$docH->loadHTMLFile($url);
//get everything inside the body element:
$bodyH = $docH->getElementsByTagName('body')->item(0);
foreach ($bodyH->childNodes as $childNode) {
echo $docH->saveHTML($childNode);
}
Parsed HTML Table:
<table>
<tr>
<td>5CG</td>
<td>aass</td>
<td>sxs</td>
<td>sx</td>
<td>EK</td>
<td></td>
<td>72</td>
</tr>
<td></td>
<td>samplxs</td>
<td>xs</td>
<td></td>
<td>xss</td>
<td>fkxsx aus</td>
<td>s</td>
</tr>
<td></td>
<td>5AH.</td>
<td>ds</td>
<td>d</td>
<td>sdf</td>
<td>sdfsdf aus</td>
<td></td>
</tr>
<tr>
<td>6CG</td>
<td>3.</td>
<td>sfd</td>
<td></td>
<td>scs</td>
<td>das aus</td>
<td>a</td>
</tr>
<tr>
<td>7DG</td>
<td>6.</td>
<td>s</td>
<td>s</td>
<td>sD</td>
<td>sdsa.</td>
<td></td>
</tr>
<td></td>
<td>samplxs</td>
<td>xs</td>
<td></td>
<td>xss</td>
<td>fkxsx aus</td>
<td>s</td>
</tr>
<tr>
<td>7DG, 7CG, 7CR</td>
<td>6.</td>
<td>NsdR</td>
<td>s</td>
<td>SP</td>
<td>fasdlt aus</td>
<td>s</td>
</tr>
<td></td>
<td>samplxs</td>
<td>xs</td>
<td></td>
<td>xss</td>
<td>fkxsx aus</td>
<td>s</td>
</tr>
<tr>
<td>9BR</td>
<td>6.</td>
<td>FEI</td>
<td>sa</td>
<td>DE</td>
<td>fasdad aus</td>
<td></td>
</tr>
<tr>
<td>9AR, 9BR, 9CR</td>
<td>62.</td>
<td>BEH</td>
<td></td>
<td>sd</td>
<td>fasda aus</td>
<td></td>
</tr>
<tr>
<td></td>
<td>6.</td>
<td>MLR</td>
<td></td>
<td>FdR</td>
<td>fsdfaus</td>
<td></td>
</tr>
<tr>
<td>E10C</td>
<td>6.</td>
<td>sdf</td>
<td>d</td>
<td>d</td>
<td>fsdfs aus</td>
<td></td>
</tr>
<tr>
</table>
But my goal is to just show the content of the table the user wants by asking for just the <tr> elements in which the first <td> of the first <tr> includes some text until there is another <tr> which first <td> has a different content.
For example: If the user types "9BR" into an input field, I just want him to see:
9BR
6.
FEI
sa
DE
fasdad aus
9AR, 9BR, 9CR
62.
BEH
sd
fasda aus
6.
MLR
FdR
fsdfaus
If he types in 5CG:
<tr>
<td>5CG</td>
<td>aass</td>
<td>sxs</td>
<td>sx</td>
<td>EK</td>
<td></td>
<td>72</td>
</tr>
<td></td>
<td>samplxs</td>
<td>xs</td>
<td></td>
<td>xss</td>
<td>fkxsx aus</td>
<td>s</td>
</tr>
Or if 6CG just:
<tr>
<td>6CG </td>
<td>3. </td>
<td>sfd </td>
<td> </td>
<td>scs </td>
<td>das aus</td>
<td>a </td>
</tr>
Using XPath, something like this should do the trick
http://de3.php.net/manual/en/class.domxpath.php
$xpath = new DomXpath($docH);
$trs = $xpath->query('//tr[td[1][contains(text(), "BR9")]]');
find all tr which first td contains text "anything"
as for the following ´tr´s with empty first td
this might not be the most elegant form to query this, but would work:
$query = '
//tr[td[1][contains(text(), "anything")]]
|
//tr[td[1][contains(text(), "anything")]]
/following-sibling::tr[td[1][not(text())] and preceding-sibling::tr[1][td[1][not(text()) or contains(text(), "anything")]]]
';
find all tr which first td contains text "anything"
also find all tr which first td is empty and whose preceding siblings (trs) first td
is also empty or contains text "anything"
example: http://3v4l.org/q6eDu

Categories