Table rowspan issue - php

I have the following table. The header is at it looks and the content is generated within a PHP loop. It contains some taxes that a user has to pay and a tax can be paid in installments. For example, if the user has to pay a 100$ tax and he first pays 25$ and then 75$, there will be two rows in the table for that tax.
What I seem to fail to accomplish is to make a rowspan so the tax name will be displayed only once.
Any help is appreciated.
<table cellpadding="0" cellspacing="0" width="100%" class="sortable">
<thead>
<tr>
<th width="10%">Tax name</th>
<th width="10%">Value</th>
<th width="10%">Paid</th>
<th width="10%">Rest</th>
</tr>
</thead>
<tbody>
<tr>
<td>Sign-up tax</td>
<td>100$</td>
<td>25$</td>
<td>75$</td>
</tr>
<tr>
<td>Sign-up tax</td>
<td>100$</td>
<td>75$</td>
<td>0$</td>
</tr>
</tbody>
</table>
The PHP code looks like this:
<?php for ($i = 0; $i < count($tax_details); $i++): ?>
<tr>
<td><?php echo $tax_details[$i]['name']; ?></td>
<td><?php echo $tax_details[$i]['value']; ?></td>
<td><?php echo $tax_details[$i]['paid']; ?></td>
<td><?php echo $tax_details[$i]['rest']; ?></td>
</tr>
<?php endfor; ?>

replace the html with this:
<tbody>
<tr>
<td rowspan="2">Sign-up tax</td> <---add rowspan here
<td>100$</td>
<td>25$</td>
<td>75$</td>
</tr>
<tr>
<td>100$</td> <---remove second sign-up tax from here
<td>75$</td>
<td>0$</td>
</tr>
</tbody>

Your code looks correct, I don't see the problem.
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="sortable">
<thead>
<tr>
<th width="10%">Tax name</th>
<th width="10%">Value</th>
<th width="10%">Paid</th>
<th width="10%">Rest</th>
</tr>
</thead>
<tbody>
<?php for ($i = 0; $i < count($tax_details); $i++): ?>
<tr>
<td><?php echo $tax_details['name']; ?></td>
<td><?php echo $tax_details['value']; ?></td>
<td><?php echo $tax_details['paid']; ?></td>
<td><?php echo $tax_details['rest']; ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
I fail to understand what you are asking.

Related

adding inline CSS in datatable row on condition not working

I tried to highlight records whose certain columns have some values other than NULL. I'm using dataTable plugin.
<table class="table table-striped table-hover" id="checkin-checkout-record-table">
<thead>
<tr>
<th>Employee Name</th>
<th>Check-in-date</th>
<th>Check-in-time</th>
<th>Check-out-date</th>
<th>Check-out-time</th>
<th class="col-lg-2">Late Check-in Remarks</th>
<th class="col-lg-2">Early Check-out Remarks</th>
</tr>
</thead>
<tbody>
<?php
foreach ($checkinCheckoutList as $member): ?>
<tr <?php
if(isset($member['early_checkout_remarks']) ||isset($member['delayed_checkin_remarks']))
{?>
style="background-color:red;"
<?php } ?> >
<td><?php echo $member['fullname'] ?></td>
<td> <?php echo $member['checkin_date']; ?></td>
<td> <?php echo $member['checkin_time']; ?></td>
<td><?php echo $member['checkout_date']; ?></td>
<td><?php echo $member['checkout_time']; ?></td>
<td><?php echo $member['delayed_checkin_remarks']; ?></td>
<td><?php echo $member['early_checkout_remarks']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
But the result is not as expected. Some records are not highlighted. This works well with other normal table. Please help.

Table inside nested Table

I am having a nested table with a while loop, I want to add one more nested table in the same row:
Now I want to add one more nested table as each cd contains more than one data like below:
My code is as follows
<?php
if(isset($_POST['viewcd'])){
$queryw = "select * from lib_cd where id=".$_POST['idd'];
$resultw = $mysqli->query($queryw);
?>
<div>
<table border="1">
<thead>
<tr ><th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th>CD No:</th>
<th >Logs</th>
</tr>
</thead>
<?php
while($rowcd = $resultw->fetch_assoc()){
?>
<tr>
<td><?php echo $rowcd['id'] ?> </td>
<td><?php echo $rowcd['well_no'] ?></td>
<td><?php echo $rowcd['well_name'] ?></td>
<td>
<table border="1" width="100%">
<?php
$querycd = "select * from cd where pidd=".$rowcd['id'];
$resultcd = $mysqli->query($querycd);
while($rowcd = $resultcd->fetch_assoc()){
?>
<tr>
<td ><?php echo $rowcd['cd_no'] ?></td>
/* I want to add one more nested table here*/
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
}
?>
</table>
</div>
I tried some thing like this,after my second while loop
while($rowcd = $resultcd->fetch_assoc()){
?>
<tr>
<td ><?php echo $rowcd['cd_no'] ?></td>
<td>
<table>
<?php
$queryl = "select * from lib_cd_logs where pid=".$rowcd['cd_no'];
$resultl = $mysqli->query($queryl);
while($rowl = $resultl->fetch_assoc()){
?>
<tr>
<td><?php echo $rowl['logs'] ?></td>
</tr>
<?php
}
?>
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
}
?>
</table>
</div>
but the result was messed up. I am confused, where I want to end my while loop, I think.
Finally i got as i wish, and i am sharing the code as below
<?php
if(isset($_POST['viewcd'])){
$queryw = "select * from lib_cd where id=".$_POST['idd'];
$resultw = $mysqli->query($queryw);
?>
<div class="container">
<table border="1" align="center" border-collapse="collapse">
<thead>
<tr >
<th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th width="100">CD No:</th>
<th width="150">Logs</th>
<th width="100">Bottom Depth</th>
<th width="100">Top Depth</th>
<th width="100">Date of Log</th>
</tr>
</thead>
<?php
while($rowcd = $resultw->fetch_assoc()){
?>
<tr>
<td><?php echo $rowcd['id'] ?> </td>
<td align="center"><?php echo $rowcd['well_no'] ?></td>
<td align="center"><?php echo $rowcd['well_name'] ?></td>
<td colspan="5">
<table rules="all">
<tr>
<?php
$querycd = "select * from cd where pidd=".$rowcd['id'];
$resultcd = $mysqli->query($querycd);
while($rowcd = $resultcd->fetch_assoc()){
?>
<td width="100" align="center"><?php echo $rowcd['cd_no'] ?></td>
<td colspan="4">
<table rules="all">
<tr>
<?php
$queryl = "select * from lib_cd_logs where pid=".$rowcd['cd_no'];
$resultl = $mysqli->query($queryl);
while($rowl = $resultl->fetch_assoc()){
?>
<td width="155"><?php echo $rowl['logs'] ?></td>
<td width="105" align="center"><?php echo $rowl['bottom'] ?></td>
<td width="100" align="center"><?php echo $rowl['top'] ?></td>
<td width="100" align="right"><?php echo $rowl['date'] ?></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
?>
</table>
</td>
<?php
}
}
?>
</tr>
</table>
I hope this is what you meant as per your data table shown above
<div>
<table border="1">
<thead>
<tr ><th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th>CD No:</th>
<th >Logs</th>
</tr>
</thead>
<tr>
<td>id</td>
<td>well</td>
<td>name</td>
<td>
<table border="1" width="100%">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</table>
</td>
<td>
<table border="1" width="100%">
<tr>
<td>Log1</td>
</tr>
<tr>
<td>Log2</td>
</tr>
</table>
</td>
</tr>
</table>
</div>

How can I stop repetition if row data same in column using PHP and MySQL

Here is my code. I am newer in programming. If I made any mistake please help me to solve it.
Thanks.
<table class="table table-striped" style="width:1300px; font-size:30px;" border="1px solid black">
<tr>
<th>Reference No</th>
<th>Category</th>
<th>Total Price</th>
</tr>
<?php
include("../db/db.php");
$sql_cost_details="select b.* from lc_details a, cost_details b where b.reference_no=a.reference_no AND a.lc_details_no='$lc_no' order by reference_no ASC";
$run_sql=mysqli_query($con, $sql_cost_details);
$i=0;
$total=0;
while($row_cost_details=mysqli_fetch_array($run_sql)){
$reference_no=$row_cost_details['reference_no'];
$category=$row_cost_details['category'];
$total_price=$row_cost_details['value'];
$i++;
?>
<tr align="center">
<td><?php echo $reference_no; ?></td>
<td><?php echo $category; ?></td>
<td><?php echo $total_price; ?></td>
</tr>
<?php } ?>
</table>
It shows this type of result
Expected result is this:
Use the below which solve your problem:
<table class="table table-striped" style="width:1300px; font-size:30px;" border="1px solid black">
<tr>
<th>Reference No</th>
<th>Category</th>
<th>Total Price</th>
</tr>
<?php
include("../db/db.php");
$sql_cost_details="select b.* from lc_details a, cost_details b where b.reference_no=a.reference_no AND a.lc_details_no='$lc_no' order by reference_no ASC";
$run_sql=mysqli_query($con, $sql_cost_details);
$i=0;
$total=0;
$prev = '';
while($row_cost_details=mysqli_fetch_array($run_sql)){
$reference_no=$row_cost_details['reference_no'];
$category=$row_cost_details['category'];
$total_price=$row_cost_details['value'];
$i++;
?>
<tr align="center">
<td><?php if ($prev != $reference_no){ echo $reference_no; } ?></td>
<td><?php echo $category; ?></td>
<td><?php echo $total_price; ?></td>
</tr>
<?php
$prev = $row_cost_details['reference_no'];
} ?>
</table>

While Loop For Table PHP

I'm trying to do this in while loop PHP, number of assignments are unlimited so rowspan should also adjust itself with the number of rows, is there any proper way to do it with minimum numbers of line?
<table border="1" cellpadding="5" cellspacing="0">
<thead>
<tr>
<th>Assignment No</th>
<th>Student Name</th>
<th>Assignment Marks</th>
<th>Overall Result</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">1</td>
<td align="center">S1</td>
<td align="center">5</td>
<td rowspan="3" align="center">B Grade</td>
</tr>
<tr>
<td align="center">2</td>
<td align="center">S1</td>
<td align="center">8</td>
</tr>
<tr>
<td align="center">3</td>
<td align="center">S1</td>
<td align="center">7</td>
</tr>
</tbody>
</table>
Try This:
<? foreach($dataarray as $data)
{?>
<tbody>
<tr>
<td align="center"><? echo $data[0]; ?></td>
<td align="center"><? echo $data[1]; ?></td>
<td align="center"><? echo $data[2]; ?></td>
</tr>
<? if($data[3]!=Null) { ?>
<td rowspan="3" align="center"><? echo $data[3]; ?></td>
<? } ?>
<? } ?>
and put if condition for last column
Assuming that data comes in a linear fashion (ie a plain one dimensional array), and that the grade is not in the array, I'd do something like this:
<?
$sizeofArray = count($data);
$rowspan = floor($sizeofArray/3);
for($arrCnt = 0; $arrCnt < $sizeofArray; $arrCnt +=3)
{?>
<tbody>
<tr>
<td align="center"><?=$data[$arrCnt]; ?></td>
<td align="center"><?=(($arrCnt+1 < $sizeofArray)?$data[$arrCnt+1]:" "); ?></td>
<td align="center"><?=(($arrCnt+2 < $sizeofArray)?$data[$arrCnt+2]:" "); ?></td>
</tr>
<? if($data[3]!=Null) { ?>
<td rowspan="<?=$rowspan?>" align="center"><?=$grade; ?></td>
<? } ?>
<? } ?>
EDIT: added "padding" code, to avoid index out of bounds error
Based on your case, rowspan is different from one student to another. What you would want to do, is group data by student. The number of assignments per student is what will give you rowspan value.
While ... {
$data['student'][] = ['name' => $row -> name]; // all student inf
$data['student][]['assignments'][] = ['id' => $row -> assignement_id];//student assigments
}
Hope this help or put in the right direction to resolve your problem.
use foreach to loop
foreach ($data as $student){
$rowspan = count($student['assignments'];
foreach ($student['assigments'] as $assignment ){
// html table
}
}

Product Specification in table grid view in magento..!

I m inserting the data in description in magento...!!
but I'm getting a paragraph...!!
but inorder to get tabular format I had to write the HTML code manually.
So is there any solutions to get the tabular format autmatically.
For example follow below pic:
Create maximum attributes for specification add those.
like spec_1.spec_2,......
then display those attributes values in specification section in table format.
For example:
<table class="data-table" id="product-attribute-specs-table-4">
<col width="25%" />
<col />
<tbody>
<?php if (0 == strcmp($attributeSetName, 'Clothing')): ?>
<tr>
<th class="label">Clothing Shape</th>
<td class="data"><?php echo $_product->getClothing_shape() ?></td>
</tr>
<tr>
<th class="label">Outer Fabric</th>
<td class="data"><?php echo $_product->getOuter_fabric() ?></td>
</tr>
<tr>
<th class="label">Clothing Lining</th>
<td class="data"><?php echo $_product->getClothing_lining() ?></td>
</tr>
<?php elseif (0 == strcmp($attributeSetName, 'Sleeping Bags')): ?>
<tr>
<th class="label">Outer Fabric</th>
<td class="data"><?php echo $_product->getOuter_fabric() ?></td>
</tr>
<tr>
<th class="label">Inner Fabric</th>
<td class="data"><?php echo $_product->getInner_fabric() ?></td>
</tr>
<tr>
<th class="label">Filling</th>
<td class="data"><?php echo $_product->getFilling() ?></td>
</tr>
<?php endif; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table-4')</script>

Categories