mysql - How Can I Break the Output from same result a PHP While Loop? -


for example in while loop result displayed order vehicle numbers this

vehicle num    total_amount test v 1234    500 test v 1234    500 test v 1234    500 test w 785     1000 test w 785     1000 test z 589     700 test z 589     700 test z 589     700  want this.  vehicle num    total_amount test v 1234    500 test v 1234    500 test v 1234    500  vehicle no: test v 1234 total amount: 1500  test w 785     1000 test w 785     1000  vehicle no: test w 785 total amount: 2000   test z 589     700 test z 589     700 test z 589     700  vehicle no: test z 589 total amount: 2100 

i want display dis using php + mysql how solve problem, can tell?

here code example?

<table class="table table-table-striped accord-content even" width="100%" style="clear:both;" id="textttt">   <thead>     <tr class="bg-green" style="background:#dbb74e!important; color:#698602 !important" >       <th>s no</th>       <th>owner name</th>       <th>truck number</th>       <th>total</th>     </tr>   </thead>   <?php  $query_all = mysql_query("select * testing ownername='" . $_post['ownername'] . "' , dc_date between '".$weekenddate."'   ,   '" . $_post['datewe'] . "' , status='verified' order truckk_number asc");          while ($fet_all = mysql_fetch_array($query_all)) {  ?>   <tr class="accord-content bg-gray" style="color:#698602 !important;">     <td><?php echo $fet_all['id']; ?></td>     <td><?php echo $fet_all['ownername']; ?></td>     <td><?php echo $fet_all['truckk_number']; ?></td>     <td><?php echo $fet_all['total']; ?></td>   </tr>   <?php   } ?> </table> 

i want display vehicle wise total , vehicle number.

because there no code in question, use pseudo code here

set track = null, total = 0 loop through collection     if track not null , current item vehicle_num different track         print current vehicle_num         print total         set total = 0     else         update total = total + current total_amount     endif     set track = current item vehicle_num     print current item info endloop 

for code, consider replacing piece:

while ($fet_all = mysql_fetch_array($query_all)) {  ?>   <tr class="accord-content bg-gray" style="color:#698602 !important;">     <td><?php echo $fet_all['id']; ?></td>     <td><?php echo $fet_all['ownername']; ?></td>     <td><?php echo $fet_all['truckk_number']; ?></td>     <td><?php echo $fet_all['total']; ?></td>   </tr>   <?php   } ?> 

to this:

<?php  #other code  $track = null; $total = 0;  while ($fet_all = mysql_fetch_array($query_all)) :?>       <?php if ($track !== null && $track !== $fet_all['truckk_number']): ?>     <tr>         <td colspan="3">vehicle no:</td>         <td><?php echo $track; ?></td>     </tr>     <tr>         <td colspan="3">total:</td>         <td><?php echo $total; ?></td>     </tr>     <?php $total = $fet_all['total']; ?>   <?php else: ?>     <?php $total += $fet_all['total'];  ?>   <?php endif; ?>   <tr class="accord-content bg-gray" style="color:#698602 !important;">     <td><?php echo $fet_all['id']; ?></td>     <td><?php echo $fet_all['ownername']; ?></td>     <td><?php echo $fet_all['truckk_number']; ?></td>     <td><?php echo $fet_all['total']; ?></td>   </tr>   <?php $track = $fet_all['truckk_number']; //add line ?> <?php endwhile; ?> <?php if ($total > 0): ?>     <tr>         <td colspan="3">vehicle no:</td>         <td><?php echo $track; ?></td>     </tr>     <tr>         <td colspan="3">total:</td>         <td><?php echo $total; ?></td>     </tr> <?php endif; ?> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -