How can I make every 4 columns it's own row in a table? Please don't tell me I should do them as div's, this needs to be a table...
Here's my code:
$tmpRet = array_filter($ret, function($e){
return ($e['categoryID'] == 6) ? $e : null;
});
$tmpRet = array_values($tmpRet);
$tmpCt = count($tmpRet);
$counter = 0;
echo '<table width="100%" cellpadding="10" cellspacing="5">' . PHP_EOL;
for($i = 0; $i < $tmpCt; ++$i){
$counter ++;
echo ($i == 0 || $i % 4 === 0) ? ' <tr>' . PHP_EOL : null;
echo '<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/' . GetLogoPath($tmpRet[$i]['showType']) . '/images/sponsors/' . $tmpRet[$i]['sponFileName'] . '" alt="' . $tmpRet[$i]['sponName'] . '" title="' . $tmpRet[$i]['sponName'] . '" style="max-height:85px;" /></td>' . PHP_EOL;
echo ($i == 0 || $i % 4 === 0) ? ' </tr>' . PHP_EOL : null;
}
echo '</table>';
And It's spitting out:
<table width="100%" cellpadding="10" cellspacing="5">
<tr>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/ADP_logo_tag_R_rgb 4-11-13.jpg" alt="ADP" title="ADP" style="max-height:85px;" /></td>
</tr>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Ascensus - color.jpg" alt="Ascensus" title="Ascensus" style="max-height:85px;" /></td>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Bridgepoint 2012.JPG" alt="Bridgepoint" title="Bridgepoint" style="max-height:85px;" /></td>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/BrightScope_Logo JPEG 10-10-12 approved.jpg" alt="BrightScope" title="BrightScope" style="max-height:85px;" /></td>
<tr>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Corporate Insight Logo JPEG 9-26-12.JPG" alt="Corporate Insight" title="Corporate Insight" style="max-height:85px;" /></td>
</tr>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Guardian Logo from 2011 OK.JPG" alt="Guardian" title="Guardian" style="max-height:85px;" /></td>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Infosys McCamish_natural_vert_nt jpeg.JPG" alt="Infosys McCamish" title="Infosys McCamish" style="max-height:85px;" /></td>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/INGC300.JPG" alt="ING" title="ING" style="max-height:85px;" /></td>
<tr>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/JANUS logoJPEG created 9-20-12.jpg" alt="Janus Capital Group" title="Janus Capital Group" style="max-height:85px;" /></td>
</tr>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/JP Morgan Logo for infotree.JPG" alt="JP Morgan" title="JP Morgan" style="max-height:85px;" /></td>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Newkirk a DST Co 4-23-13.JPG" alt="Newkirk" title="Newkirk" style="max-height:85px;" /></td>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Oculus_logo_v4-vert.jpg" alt="Oculus" title="Oculus" style="max-height:85px;" /></td>
<tr>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Pioneer Investments Jpeg ogo.JPG" alt="Pioneer Investments" title="Pioneer Investments" style="max-height:85px;" /></td>
</tr>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/ProcessUnity logo JPEG created 9-20-12.jpg" alt="ProcessUnity" title="ProcessUnity" style="max-height:85px;" /></td>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/Prudential Blue Gray for Lanyards.JPG" alt="Prudential" title="Prudential" style="max-height:85px;" /></td>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/RR Donnelley Logo for Mints.JPG" alt="RR Donnelley" title="RR Donnelley" style="max-height:85px;" /></td>
<tr>
<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/spark-forum/images/sponsors/sp_capitaliq_fc_logo.jpg" alt="S&P Capital IQ" title="S&P Capital IQ" style="max-height:85px;" /></td>
</tr>
</table>
Try replace the relevant lines in your code with these:
// At column 0 you create a new row <tr>
echo $i % 4 == 0 ? "<tr>\n" : "";
// At column 3 you end the row </tr>
echo $i % 4 == 3 ? "</tr>\n" : "";
This creates 4 columns per row.
Edit to accommodate cases where there may be coluumns that are not a multiple of 4
echo "<table>\n";
$colSpan = 4;
$rows = 0;
for($i = 0; $i < 5; $i++) {
// At column 0 you create a new row <tr>
if($i % $colSpan == 0) {
$rows++;
echo "<tr>\n";
}
echo "<td>" . ($i + 1) . "</td>\n";
// At column 3 you end the row </tr>
echo $i % $colSpan == 3 ? "</tr>\n" : "";
}
// Say you have 5 columns, you need to create 3 empty <td> to validate your table!
for($j = $i; $j < ($colSpan * $rows); $j++) {
echo "<td></td>\n";
}
// Add the final <tr>
if(($colSpan * $rows) > $i) {
echo "</tr>\n";
}
echo "</table>\n";
And this should create near enough perfect <table></table> structure! Enjoy.
What you want to echo a </tr> right before you echo a <tr> unless it's the first time through.
echo "<tr>";
for($i = 0; $i < $tmpCt; ++$i){
$counter ++;
// echo a row close right before you row open unless it's the first one
echo ($i != 0 || $i % 4 === 0) ? ' </tr><tr>' . PHP_EOL : null;
echo '<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/' . GetLogoPath($tmpRet[$i]['showType']) . '/images/sponsors/' . $tmpRet[$i]['sponFileName'] . '" alt="' . $tmpRet[$i]['sponName'] . '" title="' . $tmpRet[$i]['sponName'] . '" style="max-height:85px;" /></td>' . PHP_EOL;
}
// close out the last row
echo "</tr>";
Try it with nested for loops:
for($i = 0; $i < $tmpCt; ++$i){
$counter ++;
echo ' <tr>' . PHP_EOL;
for($j = 0; $j < 4 && $i < $tmpCt; ++$j, ++$i){
echo '<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/' . GetLogoPath($tmpRet[$i]['showType']) . '/images/sponsors/' . $tmpRet[$i]['sponFileName'] . '" alt="' . $tmpRet[$i]['sponName'] . '" title="' . $tmpRet[$i]['sponName'] . '" style="max-height:85px;" /></td>' . PHP_EOL;
}
echo ' </tr>' . PHP_EOL;
}
One thing that might go wrong is that maybe PHP doesn't support for loops where two incrementations happen (haven't tested it), so if it doesn't, just put the ++$i at the end of the inner for loop.
This will go through 4 columns or until the last column is found. This way $j is a simple counter to 4, and $i is still the reference for the array. Now in pseudocode, it's
for(every column){
start row;
for(4 iterations){
print or use the contents of a column;
}
end row;
}
EDIT
As OrangePill suggested, this would also work
for($i = 0; $i < $tmpCt; $i+=4){
$counter ++;
echo ' <tr>' . PHP_EOL;
for($j = 0; $j < 4 && $i+$j < $tmpCt; ++$j){
echo '<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/' . GetLogoPath($tmpRet[$i+$j]['showType']) . '/images/sponsors/' . $tmpRet[$i+$j]['sponFileName'] . '" alt="' . $tmpRet[$i+$j]['sponName'] . '" title="' . $tmpRet[$i+$j]['sponName'] . '" style="max-height:85px;" /></td>' . PHP_EOL;
}
echo ' </tr>' . PHP_EOL;
}
echo '<table width="100%" cellpadding="10" cellspacing="5">' . PHP_EOL . '<tr>' . PHP_EOL;
for($i = 1; $i <= $tmpCt; ++$i){
echo '<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/' . GetLogoPath($tmpRet[$i]['showType']) . '/images/sponsors/' . $tmpRet[$i]['sponFileName'] . '" alt="' . $tmpRet[$i]['sponName'] . '" title="' . $tmpRet[$i]['sponName'] . '" style="max-height:85px;" /></td>' . PHP_EOL;
echo ($i % 4 === 0) ? ' <tr>' . PHP_EOL .'</tr>' . PHP_EOL : null;
}
for($j = 1; $j <= (4 - $tmpCT % 4); $j++){
echo '<td width="25%"> </td>' . PHP_EOL;
}
echo '</tr>' . PHP_EOL . '</table>';
You've got a couple issues.
First, you're wrapping you first and every fourth cell in a tr.
Try changing this:
echo '<table width="100%" cellpadding="10" cellspacing="5">' . PHP_EOL;
for($i = 0; $i < $tmpCt; ++$i){
$counter ++;
echo ($i == 0 || $i % 4 === 0) ? ' <tr>' . PHP_EOL : null;
echo '<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/' . GetLogoPath($tmpRet[$i]['showType']) . '/images/sponsors/' . $tmpRet[$i]['sponFileName'] . '" alt="' . $tmpRet[$i]['sponName'] . '" title="' . $tmpRet[$i]['sponName'] . '" style="max-height:85px;" /></td>' . PHP_EOL;
echo ($i == 0 || $i % 4 === 0) ? ' </tr>' . PHP_EOL : null;
}
echo '</table>';
To this:
echo '<table width="100%" cellpadding="10" cellspacing="5">' . PHP_EOL;
echo '<tr>';//start first row
for($i = 0; $i < $tmpCt; ++$i){
$counter ++;
echo '<td width="25%" align="center" valign="middle"><img border="0" src="http://sparkusa.org/' . GetLogoPath($tmpRet[$i]['showType']) . '/images/sponsors/' . $tmpRet[$i]['sponFileName'] . '" alt="' . $tmpRet[$i]['sponName'] . '" title="' . $tmpRet[$i]['sponName'] . '" style="max-height:85px;" /></td>' . PHP_EOL;
echo ($i == 0 || $i % 4 === 0) ? '</tr><tr>' . PHP_EOL : null;//end row after every fourth cell and start a new one
}
echo '</tr>';//close out last row
echo '</table>';
Depending on how your page is laying out, you may have to insert some empty table cells in the last row, in case your record count isn't evenly divisible by 4.
Related
I am trying to show results that I get from a SQL table, it is this:
what I want to do is show results 3 by 3, like this:
I mean a table for every 3 results that the "assigned_bank" field matches, and if there are 4 results with the same number in "assigned_bank", I also show it in that same table, that is; one table for each different "assigned_bank" id.
I've been trying most of the day and the closest thing I've come to is this:
This is my last code:
<?php
$tables = sizeof($search) / 3;
for ($i = 0; $i < $tables; $i++) {
?>
<table class="table customers">
<thead class="thead-blue">
<tr>
<th scope="col-xs-2">Name</th>
<th scope="col-xs-2">Lastname</th>
<th scope="col-xs-2">Bank ID</th>
</tr>
</thead>
<tbody>
<?php
foreach ($search as $item){
echo '<tr align="left">';
echo '<td class="col-xs-2">' . $item["p_name"] . '</td>' . "\r\n";
echo '<td class="col-xs-2">' . $item["p_lastname"] . '</td>' . "\r\n";
echo '<td class="col-xs-2">' . $item["assigned_bank"] . '</td>' . "\r\n";
echo '</tr>';
}
?>
</tbody>
</table>
<?php
echo "\r\n";
}
?>
Thank you very much for any possible help or comments and thank you for taking the time to respond.
<?php
$result = array();
foreach ($search as $key => $item) {
$result[$item['assigned_bank']][$key] = $item;
}
foreach($result as $key=>$search_items){
echo '<table class="table customers" border="2" >
<thead class="thead-blue">
<tr>
<th scope="col-xs-2">Name</th>
<th scope="col-xs-2">Lastname</th>
<th scope="col-xs-2">Bank ID</th>
</tr>
</thead>
<tbody>';
foreach($search_items as $skey=>$item){
echo '<tr align="left">';
echo '<td class="col-xs-2">' . $item["p_name"] . '</td>' . "\r\n";
echo '<td class="col-xs-2">' . $item["p_lastname"] . '</td>' . "\r\n";
echo '<td class="col-xs-2">' . $item["assigned_bank"] . '</td>' . "\r\n";
echo '</tr>';
}
echo '</tbody>
</table>';
}
<?>
You can use order by on assigned_bank column with ascending order:
SELECT p_name, p_lastname, assigned_bank FROM your_table order by
assigned_bank asc
I have search and implements from many question in stackoverflow to my code but it always returning only the last row value.
Here my code :
$totalpayment = 0;
foreach($respon2 as $key => $row) {
$name = $row['title'];
$quantity = $row['quantity'];
$price = $row['price']*$row['quantity'];
$totalpayment += $price;
$price = '$ ' . number_format($price) ;
$totalpayment = '$ ' . number_format($totalpayment) ;
$mytable .= '<tr width="100%">';
$mytable .= '<td width="55%" align="left">' . $name . "</td>";
$mytable .= '<td width="20%" align="right">' . $quantity . "</td>";
$mytable .= '<td width="25%" align="right">' . $price . "</td>";
$mytable .= '</tr>';
}
$mytable .= '</table>';
$mytable .= '<table border="0" cellpadding="10" cellspacing="0" width="100%%" style="padding: 0px 25px 0px 25px;">';
$mytable .= '<tr><td width="45%"></td><td width="30%" class="table-title" align="right">Total Payment:</td><td width="25%" align="right">'. $totalpayment ."</td></tr>";
$mytable .= '</table>';
How to fix this ?
You are overding $totalpayment on every loop by this code:
$totalpayment = '$ ' . number_format($totalpayment) ;
$totalpayment = 0;
foreach($respon2 as $key => $row) {
$name = $row['title'];
$quantity = $row['quantity'];
$price = $row['price']*$row['quantity'];
$totalpayment += $price;
$price = '$ ' . number_format($price) ;
$mytable .= '<tr width="100%">';
$mytable .= '<td width="55%" align="left">' . $name . "</td>";
$mytable .= '<td width="20%" align="right">' . $quantity . "</td>";
$mytable .= '<td width="25%" align="right">' . $price . "</td>";
$mytable .= '</tr>';
}
$totalpayment = '$ ' . number_format($totalpayment); //Try transferring this code outside the loop
$mytable .= '</table>';
$mytable .= '<table border="0" cellpadding="10" cellspacing="0" width="100%%" style="padding: 0px 25px 0px 25px;">';
$mytable .= '<tr><td width="45%"></td><td width="30%" class="table-title" align="right">Total Payment:</td><td width="25%" align="right">'. $totalpayment ."</td></tr>";
$mytable .= '</table>';
It is not so efficient to do a sum in loop, better change your code as follows and to be done out side the loop as mentioned in question.
$prices = sum(array_coulmn($respon2, 'price'));
$quantity = sum(array_coulmn($respon2, 'quantity'));
$totalPayment = $prices*$quantity;
$totalPayment = '$ ' . number_format($totalPayment);
$totalpayment = 0;
$mytable ='<table>';
$respon2=array(array('title' =>'p1','quantity' =>2,'price' =>10),array('title' =>'p2','quantity' =>2,'price' =>20),array('title' =>'p3','quantity' =>1,'price' =>10));
foreach($respon2 as $key => $row) {
$name = $row['title'];
$quantity = $row['quantity'];
$price = $row['price']*$row['quantity'];
$totalpayment += $price;
$price = '$ ' . number_format($price) ;
$mytable .= '<tr width="100%">';
$mytable .= '<td width="55%" align="left">' . $name . "</td>";
$mytable .= '<td width="20%" align="right">' . $quantity . "</td>";
$mytable .= '<td width="25%" align="right">' . $price . "</td>";
$mytable .= '</tr>';
}
$totalpayment = '$ ' . number_format($totalpayment) ;
$mytable .= '</table>';
$mytable .= '<table border="0" cellpadding="10" cellspacing="0" width="100%%" style="padding: 0px 25px 0px 25px;">';
$mytable .= '<tr><td width="45%"></td><td width="30%" class="table-title" align="right">Total Payment:</td><td width="25%" align="right">'. $totalpayment ."</td></tr>";
$mytable .= '</table>';
echo $mytable;
How will i Display a picture with the same id here in my pagination.php?
i tried doing this
<td width="20%" valign="top"><a href="product.php?id=' . $id . '">
<img style="border:#666 2px solid;" src="inventory_images/' . $id . '.jpg" width="150" height="102" border="1" /></a>
</td>
but it wont work.. any possible way to display the image using pagination?
for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . mysql_result($result, $i, 'product_name') . '</td>';
echo '<td>' . mysql_result($result, $i, 'price') . '</td>';
echo '<td>' . mysql_result($result, $i, 'details') . '</td>';
echo '<td>' . mysql_result($result, $i, 'category') . '</td>';
echo '<td>' . mysql_result($result, $i, 'subcategory') . '</td>';
echo '<td>Click To View</td>';
echo "</tr>";
}
Probably you have to put in your code something like that :
<td width="20%" valign="top">
<a href="product.php?id=<?php echo $id; ?>">
<img style="border:#666 2px solid;" src="inventory_images/<?php echo $id; ?>.jpg" width="150" height="102" border="1" />
</a>
</td>
Check the generated source and adjust the code above. Please keep in mind that in HTML you cannot put php variables directly. You have to output them with php echo statement like that :
<html>
SOME HTML
<div class="valueFromPhp"><?php echo $value; ?></div>
</html>
Also remebmer to escape output using htmlentities() to prevent XSS attacks.
echo '
<td>
<img width=100 src="../PHP/saved_images/'.mysql_result($result, $i, "bkimg").'">
</td>
';
I have a php file(add_member.php). I'm creating a dynamic table by executing SQL query. The code of this file is as follows:
$sql = SELECT * FROM member_details WHERE lname='ABC';
$n = new data();
$res = $n -> querySend($sql);
?>
<table border="1" cellpadding="3" cellspacing="1">
<tr>
<td align="center"></td>
<td align="center">First Name</td>
<td align="center">Last Name</td>
<td align="center">Caste</td>
<td align="center">Residence address</td>
<td align="center">Education</td>
</tr>
<?php
$i=1;
while($row = mysql_fetch_array($res))
{
$member_no = $row['member_no'];
$total_member = "SELECT COUNT(*) AS total_member FROM family_member_details WHERE member_no =" .$member_no;
$total_res = $n -> querySend($total_member);
$row_total = mysql_fetch_array($total_res);
?>
<tr>
<td align="center" rowspan="<?php echo $row_total['total_member']+1;?>"><?php echo $i;?></td>
<td align="center"><?php echo $row['fname'];?></td>
<td align="center"><?php echo $row['lname'];?></td>
<td align="center"><?php echo $row['caste'];?></td>
<td align="center"><?php echo $row['residence_addr'];?></td>
<td align="center"><?php echo $row['education'];?></td>
</tr>
<?php
$family_sql = "SELECT * from family_member_details WHERE member_no = $member_no";
$family_res = $n -> querySend($family_sql);
while($row1 = mysql_fetch_array($family_res))
{
?>
<tr>
<td align="center"><?php echo $row1['name']?></td>
<td align="center"><?php echo $row1['name']?></td>
<td align="center"><?php echo $row1['name']?></td>
<td align="center"><?php echo $row1['name']?></td>
<td align="center"><?php echo $row1['name']?></td>
</tr>
<?php }
$i++;
} ?>
</table>
Now upon clicking on a button I want to create the same table into PDF file. For this purpose I decided to use TCPDF library. But for it I've to provide the HTML content to TCPDF file. Now my issue is how should I get the HTML of a dynamically generated table from PHP file and write this content to the text file? Can anyone please help me in this regard? Any help would be highly appreciated.
Instead of displaying your table directly to the browser page, simply store the text in a variable and echo it...then you can send the var to the TCPDF library.
$dyn_table = '<table border="1" cellpadding="3" cellspacing="1"><tr><td align="center">/td><th align="center">First Name</th><th align="center">Last Name</th><th align="center">Caste</th><th align="center">Residence address</th><th align="center">Education</th></tr>';
$i = 1;
while ($row = mysql_fetch_array($res)) {
$member_no = $row['member_no'];
$total_member = "SELECT COUNT(*) AS total_member FROM family_member_details WHERE member_no =" . $member_no;
$total_res = $n->querySend($total_member);
$row_total = mysql_fetch_array($total_res);
$dyn_table .= '<tr><td align="center" rowspan="' . $row_total['total_member'] + 1 . '">' . $i . '</td><td align="center">' . $row['fname'] . '</td><td align="center">' . $row['lname'] . '</td><td align="center">' . $row['caste'] . '</td><td align="center">' . $row['residence_addr'] . '</td><td align="center">' . $row['education'] . '</td></tr>';
$family_sql = "SELECT * from family_member_details WHERE member_no = $member_no";
$family_res = $n->querySend($family_sql);
while ($row1 = mysql_fetch_array($family_res)) {
$dyn_table .= '<tr><td align="center">' . $row1['name'] . '</td><td align="center">' . $row1['name'] . '</td><td align="center">' . $row1['name'] . '</td><td align="center">' . $row1['name'] . '</td><td align="center">' . $row1['name'] . '</td></tr>';
}
$i++;
}
$dyn_table .= '</table>';
echo $dyn_table;
EDIT
In order to post this html to your TCPDF library, I would use AJAX to prevent another page request/load. I prefer to use JQuery as it simplifies this process immensely. Here is one way you could do it:
<input type="button" name="TCPDF" id="submitToTCPDF" />
<script type="text/javascript">
var url = 'php/script/to/handle/post';
var data = {'table_html': '<? echo $dyn_table; ?>'};
$('#TCPDF').click(function(){
$.ajax({
type: "POST",
url: url,
data: data,
success: function($result){
// Do whatever after html is submitted
}
});
});
</script>
You can read more about Jquery's AJAX post method in this StackOverflow question.
I have a scanner project I'm developing where a class reads in a txt file created by scanner and queries the database to display "bundles" scanner by a scanner per room. However now I have some rooms which duplicate the results. The results from the query are stop in arrays per day and manipulate. What i want to do is to display unique bundles and remove duplicates leaving the earliest entry. Below is my index page. Any tips advise would be much appreciated.
<?php
// First of all initialise the user and check for permissions
require_once "/var/www/users/user.php";
$user = new CHUser(13);
// Initialise the template
require_once "/var/www/template/template.php";
$template = new CHTemplate();
// Initialise the scanner class
require_once "/var/www/Scanners/scanners.php";
$scanner = new CHScanners();
$_GET['date'] = date("Y-m-d", $scanner->GetPreviousMonday(strtotime($_GET['date'])));
$weeklyTotal = 0;
$content = "<h1>" . $scanner->GetRoomName($_GET['room']) . " Information</h1>
<form action='room.php' method='get'>
Enter date: <input type='text' name='date' /><input type='submit' /><input type='hidden' name='room' value='" . $_GET['room'] ."' />
</form>
<table width='100%'>
<tr>
<td style='vertical-align: top;'>
<table width='100%'>
<tr>
<th colspan='2'>Monday</th>
</tr>
<tr>
<th>Bundle #</th>
<th>Qty</th>
</tr>";
$result = $scanner-
>ListRoomTotals($_GET['room'],$_GET['date']);
$total = 0;
foreach($result as $x) {
$content .= "<tr>
<td>" . $x[0] . "</td>
<td>" . $x[1] . "</td>
</tr>";
$total += $x[1];
}
$weeklyTotal += $total;
$content .= "<tr><td>Total Pairage:</td><td>".$total."
</td></tr>
<tr><td>Total Dozens:</td><td>".number_format($total/12,1)."</td></tr></table>
</td>
<td style='vertical-align: top;'>
<table width='100%'>
<tr>
<th colspan='2'>Tuesday</th>
</tr>
<tr>
<th>Bundle #</th>
<th>Qty</th>
</tr>";
$date = date("Y-m-d",(strtotime($_GET['date']) + 86400));
$result = $scanner->ListRoomTotals($_GET['room'], $date);
$total = 0;
foreach($result as $x) {
$content .= "<tr>
<td>" . $x[0] . "</td>
<td>" . $x[1] . "</td>
</tr>";
$total += $x[1];
}
$weeklyTotal += $total;
$content .= "<tr><td>Total Pairage:</td><td>" . $total . "
</td></tr>
<tr><td>Total Dozens:</td><td>" .
number_format($total/12,1) . "</td></tr></table>
</td>
<td style='vertical-align: top;'>
<table width='100%'>
<tr>
<th colspan='2'>Wednesday</th>
</tr>
<tr>
<th>Bundle #</th>
<th>Qty</th>
</tr>";
$date = date("Y-m-d",(strtotime($_GET['date']) +
(86400*2)));
$result = $scanner->ListRoomTotals($_GET['room'], $date);
$total = 0;
foreach($result as $x) {
$content .= "<tr>
<td>" . $x[0] . "</td>
<td>" . $x[1] . "</td>
</tr>";
$total += $x[1];
}
$weeklyTotal += $total;
$content .= "<tr><td>Total Pairage:</td><td>" . $total . "
</td></tr>
<tr><td>Total Dozens:</td><td>" .
number_format($total/12,1) . "</td></tr></table>
</td>
<td style='vertical-align: top;'>
<table width='100%'>
<tr>
<th colspan='2'>Thursday</th>
</tr>
<tr>
<th>Bundle #</th>
<th>Qty</th>
</tr>";
$date = date("Y-m-d",(strtotime($_GET['date']) +
(86400*3)));
$result = $scanner->ListRoomTotals($_GET['room'], $date);
$total = 0;
foreach($result as $x) {
$content .= "<tr>
<td>" . $x[0] . "</td>
<td>" . $x[1] . "</td>
</tr>";
$total += $x[1];
}
$weeklyTotal += $total;
$content .= "<tr><td>Total Pairage:</td><td>" . $total . "
</td></tr>
<tr><td>Total Dozens:</td><td>" .
number_format($total/12,1) . "</td></tr></table>
</td>
<td style='vertical-align: top;'>
<table width='100%'>
<tr>
<th colspan='2'>Friday</th>
</tr>
<tr>
<th>Bundle #</th>
<th>Qty</th>
</tr>";
$date = date("Y-m-d",(strtotime($_GET['date']) +
(86400*4)));
$result = $scanner->ListRoomTotals($_GET['room'], $date);
$total = 0;
foreach($result as $x) {
if($x[0] != "" and isset($x[0])) {
$content .= "<tr>
<td>" . $x[0] . "</td>
<td>" . $x[1] . "</td>
</tr>";
$total += $x[1];
}
}
$weeklyTotal += $total;
$content .= "<tr><td>Total Pairage:</td><td>" . $total . "
</td></tr>
<tr><td>Total Dozens:</td><td>" .
number_format($total/12,1) . "</td></tr></table>
</td>
</tr>
</table>";
$options .= "Weekly Pairs: " . $weeklyTotal . "<br>
Weekly Dozens: " . $weeklyTotal/12;
$template->SetTag("options", $options);
$template->SetTag("content", $content);
echo $template->Display();
?>
Before appending do a in_array() test.
It may be better to implement the constraint in your query than to do it in PHP. Try using group by and using min on your date to get the room with the earliest entry. Here is a relevant example on this site.
If you wish to do it inside PHP, you would have to some filter. Set up a temp array to store the final results, and loop through all your results. If the room is not in the result array, add it. If it is, compare the date and use the earliest date.