how to correct my output, this first is what I want
and this is what it did
this is my code:
<?php for( $i = 0 ; $i<count($db_charge);$i++) { ?>
<tBody id="tbl_rec">
<tr>
<td><?php
$date_date = $db_charge[$i]['dDate'];
echo $new_date = date('D-j-F-Y H:i' , strtotime($date_date)); ?></td>
<td><?php
echo $db_charge[$i]['iBalance'];
?></td>
<td> <?php
$iBal += $db_charge[$i]['iBalance'];
echo $iBal;
?>
</td>
</tr>
</tBody>
<?php } ?>
Related
I have table rowspan dynamic on CodeIgniter app like this :
<table>
<tr>
<td>No</td>
<td>Data</td>
<td>Data 2</td>
<td>Qty</td>
<td>Price</td>
<td>Sub Total</td>
<td>TOtal</td>
</tr>
<?php
$source1 = $this->db->query("select * from table")->result_array();
$no=1;
foreach($source1 as source1){ ?>
<tr>
<?php
$source2 = $this->db->query("select * from table where data1='$source1[data1]'");
$total_source2 = $source2->num_rows();
$source3 = $source2->result_array();
?>
<td rowspan="<?php echo $total_source2 ?>"><?php echo $no; ?></td>
<td rowspan="<?php echo $total_source2 ?>"><?php echo $source1['data1']; ?></td>
<?php foreach($source3 as $source3){ ?>
<td><?php echo $source3['data2'] ?></td>
<td><?php echo $source3['qty'] ?></td>
<td><?php echo $source3['price'] ?></td>
<td><?php echo $source3['sub_total'] ?></td>
<td><?php echo $source3['total'] ?></td>
</tr>
<?php } ?>
<?php $no++; } ?>
</table>
This is result of my code:
How to make it like this
?
Thanks.
This is about as efficient as anything I can come up with without the actual SQL file and I'm not sure if it works:
<table>
<tr>
<td>No</td>
<td>Data</td>
<td>Data 2</td>
<td>Qty</td>
<td>Price</td>
<td>Sub Total</td>
<td>Total</td>
</tr>
<?php
$source1 = $this->db->query("select * from table")->result_array();
$no = 1;
foreach ($source1 as $source1) {
?>
<tr>
<?php
$source2 = $this->db->query('select * from table where data1 = ' . $source1['data1']);
$total_source2 = $source2->num_rows();
$source3 = $source2->result_array();
$rowspan = true;
?>
<td rowspan="<?php echo $total_source2 ?>"><?php echo $no; ?></td>
<td rowspan="<?php echo $total_source2 ?>"><?php echo $source1['data1']; ?></td>
<?php foreach ($source3 as $source3) { ?>
<td><?php echo $source3['data2'] ?></td>
<td><?php echo $source3['qty'] ?></td>
<td><?php echo $source3['price'] ?></td>
<td><?php echo $source3['sub_total'] ?></td>
<?php
if ($rowspan) {
$q = $this->db->query('SELECT SUM(`sub_total`) as `nb` FROM `table` WHERE `data1` = ' . $source1['data1']);
echo "<td rowspan='{$total_source2}'>" . $q->row()->nb . '</td>';
$rowspan = false;
}
?>
</tr>
<?php } ?>
<?php
$no++;
}
?>
</table>
I want 3 elements of array to be displayed before setTimeout(30000) function and 3 elements after it;so that there is gap of 30 seconds between both the loops.But I am not getting the desired result.Following is the code:
<?php
$info=array(array("name"=>"abc",
"phone"=>"12345"),
array("name"=>"pqr",
"phone"=>"23456"),
array("name"=>"def",
"phone"=>"34567"),
array("name"=>"asd",
"phone"=>"45678"),
array("name"=>"ghj",
"phone"=>"56789"),
array("name"=>"jkl",
"phone"=>"67566"),
);
echo ( $info[0]["name"]);
?>
<body>
<table>
<tr>
<th>id</th>
<th>Name</th>
<th>phone<th>
</tr>
<?php
$i=1;
foreach ($info as $data) {
if($i==4)
{
break;
}
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $data["name"]; ?></td>
<td><?php echo $data["phone"]; ?></td>
</tr>
<?php $i++;}?>
<script>
window.setTimeout(30000);
</script>
<?php
for($j=3;$j<6;$j++)
{
?>
<tr>
<td><?php echo $j+1; ?></td>
<td><?php echo $info[$j]["name"]; ?></td>
<td><?php echo $info[$j]["phone"]; ?></td>
</tr>
<?php } ?>
</table>
I am having a problem about showing total in groups.
Here is my scenario, I have a report grouped by area and by product.
What I already have is the row for area group.
What I want to do is to show the total qty of product per area before the row for the next group. Currently, it shows the total after every row.
Here is my code.
<?php if (isset($summaryPerArea)): ?>
<div class="col-lg-12">
<table id="" class="table table-bordered table-condensed table-striped">
<thead>
<tr>
<th>Area</th>
<th>Material</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<?php
$prevArea = '';
$total = 0;
$currentQty = 0;
?>
<?php foreach ($summaryPerArea as $key => $value): ?>
<?php $currentQty = $value['totalQty']; ?>
<?php $total += $value['totalQty']; ?>
<?php if ($value['area'] != $prevArea): ?>
<tr class="bg-info">
<?php if ($key != 0) {$total = $currentQty;} ?>
<td colspan="3"><?php echo $value['area']; ?></td>
<?php $prevArea = $value['area']; ?>
</tr>
<?php endif; ?>
<tr>
<td><?php echo $value['area']; ?></td>
<td><?php echo $value['material']; ?></td>
<td><?php echo $value['totalQty']; ?></td>
</tr>
<?php if ($value['area'] == $prevArea): ?>
<tr class="bg-success">
<td colspan="3"><?php echo $total; ?></td>
</tr>
<?php endif; ?>
<?php endforeach ?>
</tbody>
</table>
</div>
<?php endif ?>
query:
SELECT d.SOffcNm as area,
c.ProdNm as material,
SUM(Qty) as totalQty
FROM BigEMerchandiser.dbo.tbl_Delivery_H as a
INNER JOIN BigEMerchandiser.dbo.tbl_Delivery_D as b
ON a.TransCtr = b.TransCtr
INNER JOIN BigESales.dbo.tbl_Materials as c
ON b.Material = c.ExtMatGrp
INNER JOIN BigESales.dbo.tbl_Customers as d
ON a.CustCode = d.CustCode
WHERE d.SOffc LIKE ISNULL('%' + #area + '%', d.SOffc)
AND a.DtRcv BETWEEN #DtRcvFrom AND #DtRcvTo
GROUP BY d.SOffcNm,
c.ProdNm
ORDER BY d.SOffcNm asc
current result:
Thankyou. I appreciate your help.
try to change your code according to the comments in the code below (only the foreach part)
<?php foreach ($summaryPerArea as $key => $value): ?>
<?php if ($value['area'] != $prevArea and $prevArea): // show total when changing area from second area onward ?>
<tr class="bg-success">
<td colspan="3"><?php echo $total; ?></td>
</tr>
<?php $total = 0; // reset the total after displaying it ?>
<?php endif; ?>
<?php if ($value['area'] != $prevArea):// show area header at every area change ?>
<tr class="bg-info">
<td colspan="3"><?php echo $value['area']; ?></td>
</tr>
<?php endif; ?>
<?php //$currentQty = $value['totalQty']; // does not needed ?>
<?php $total += $value['totalQty']; ?>
<tr>
<td><?php echo $value['area']; ?></td>
<td><?php echo $value['material']; ?></td>
<td><?php echo $value['totalQty']; ?></td>
</tr>
<?php $prevArea = $value['area']; // set prevArea to the processed row ?>
<?php endforeach ?>
<?php // show the last total ?>
<tr class="bg-success">
<td colspan="3"><?php echo $total; ?></td>
</tr>
notice that the order of the rows are repeated as follows:
--area total--
--area header--
--area item--
and followed by:
--area total--
on the first foreach, prevArea is still '' so the first condition in the --area total-- (and $prevArea) would result in false, so that the --area total-- is suppressed, but the --area header-- does not have that condition, so the --area header-- is not suppressed.
I use a different syntax of php, using if(condition){code};
If I understood your problem, I make a different solution, I controll if the next is different from the value that i use now, because if it was different you need to print.
I rewrite your code like this:
<tbody>
<?php
$prevArea = 'AnElementLikeFlag';
$total = 0;
$currentQty = 0;
?>
<?php foreach ($summaryPerArea as $key => $value): ?>
<?php $currentQty = $value['totalQty']; ?>
<?php if ($value['area'] != $prevArea && $value['area']!="AnElementLikeFlag"): ?>
<tr class="bg-success">
<td colspan="3"><?php echo $total; ?></td>
</tr>
<tr class="bg-info">
<td colspan="3"><?php echo $value['area']; ?></td>
<?php $prevArea = $value['area']; ?>
</tr>
<?php $total=0; ?>
<?php endif; ?>
<?php $total += $value['totalQty']; ?>
<tr>
<td><?php echo $value['area']; ?></td>
<td><?php echo $value['material']; ?></td>
<td><?php echo $value['totalQty']; ?></td>
</tr>
<?php endforeach ?>
</tbody>
I hope I help you and I maybe make an error.
P.S. You print the total every time, because there is a if condition that it is not necessery
I attached my output image here: this my output
<table width="100%" style="text-align:center">
<tr>
<td>Subject </td>
<td>Grade </td>
</tr>
<?php
include 'connect.php';
$class_n =$_POST['class_n'];
$class_s =$_POST['class_s'];
$r =$_POST['roll'];
$sql="select * from full_result where class_n='$class_n' AND class_s='$class_s' AND roll='$r'";
$data = mysql_query($sql);
$sum=0;
while ($row = mysql_fetch_array($data))
{
$r=$row['marks'];
if($r>=40)
{
$r1=$row['point'];
}
elseif($r<=33)
{
$r1=0;
}
$sum=$sum+$r1;
?>
<tr>
<td><?php echo $row['subject']; ?></td>
<td><?php echo $row['grade']; ?> </td>
<td><?php echo $row['point']; ?> </td>
</tr>
<?php } ?>
</table>
<br>
<p><?php echo $sum;
?> </p>
This my code, here I am trying to use one condition, but it's doesn't work. it comes almost total Marks. But what I want is that when any subject becomes 0 or F, the Total mark will become F.
Use a flag variable and set it to 1 if the student get 0 or F (I assume it's when $r <= 33) for any subject. Then before displaying sum, check if the flag is set and if set change value of $sum to 'F'
<table width="100%" style="text-align:center">
<tr>
<td>Subject </td>
<td>Grade </td>
</tr>
<?php
include 'connect.php';
$class_n =$_POST['class_n'];
$class_s =$_POST['class_s'];
$r =$_POST['roll'];
$flag = 0;
$sql="select * from full_result where class_n='$class_n' AND class_s='$class_s' AND roll='$r'";
$data = mysql_query($sql);
$sum=0;
while ($row = mysql_fetch_array($data))
{
$r=$row['marks'];
if($r>=40)
{
$r1=$row['point'];
}
elseif($r<=33)
{
$r1=0;
$flag = 1;
}
$sum=$sum+$r1;
?>
<tr>
<td><?php echo $row['subject']; ?></td>
<td><?php echo $row['grade']; ?> </td>
<td><?php echo $row['point']; ?> </td>
</tr>
<?php }
if($flag == 1)
{
$sum = F;
}
?>
</table>
<br>
<p><?php echo $sum; ?>
?> </p>
My problem is that I can't fill my table with the data I got in my database. I wrote a code in PHP to do it but it doesn't work and I don't know how to make it work. Any idea ? Here's my code :
view gestJury :
<h3>Liste des jurys :</h3>
<div class="tablebox">
<table>
<thead>
<tr>
<th>N°</th>
<th>Professeur1</th>
<th>Professeur2</th>
<th>Salle</th>
<th>Heure</th>
<?php if($rang == 0){ ?>
<th class="action" >Supprimer</th>
<?php } ?>
</tr>
</thead>
<?php $i = 0; ?>
<?php while($donnees = $listeJury->fetch(PDO::FETCH_ASSOC)){
$i = $i + 1;
?>
<tbody>
<tr class="row0">
<td><?php echo $donnees['idJury'] ?></td>
<td><?php echo $donnees['idProf'] ?></td>
<td><?php echo $donnees['idProf2'] ?></td>
<td><?php echo $donnees['Salle'] ?></td>
<td><?php echo $donnees['horaireJury'] ?></td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
index.php :
function listJuryGlobal(){
$jury = new Professeur();
$listeJury = $jury->getJuryGlobal();
require('view/gestJury.php');
}