Advertisement
raditart

Report (looping inside looping)

Feb 23rd, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.28 KB | None | 0 0
  1. <?php
  2.   ob_start();
  3.   //include("koneksi.php");
  4. $servername = "localhost";
  5. $username = "root";
  6. $password = "";
  7. $dbname = "javiscoi_task";
  8.  
  9. // Create connection
  10. $conn = new mysqli($servername, $username, $password, $dbname);
  11. // Check connection
  12. if ($conn->connect_error) {
  13.     die("Connection failed: " . $conn->connect_error);
  14. }
  15.  
  16.  
  17.  
  18.  
  19.   session_start();    
  20.   $id_project = $_GET['id_project'];
  21. ?>
  22. <!DOCTYPE html>
  23. <html lang="en">
  24. <head>
  25.   <meta charset="UTF-8">
  26. <title>Purchase Order</title>  
  27. <style>
  28. body {
  29.   background: rgb(204,204,204);
  30. }
  31. page {
  32.   background: white;
  33.   display: block;
  34.   margin: 0 auto;
  35.   margin-bottom: 0.5cm;
  36.   box-shadow: 0 0 0.5cm rgba(0,0,0,0.5);
  37. }
  38. page[size="A4"] {  
  39.   width: 21cm;
  40.  
  41. }
  42. page[size="A4"][layout="portrait"] {
  43.   width: 29.7cm;
  44.   height: 21cm;  
  45. }
  46.  
  47. @media print {
  48.   body, page {
  49.     margin: 0;
  50.     box-shadow: 0;
  51.   }
  52. }
  53. .button {
  54.     background-color: #2a3f54;
  55.     border: none;
  56.     color: white;
  57.     padding: 10px;
  58.     text-align: center;
  59.     text-decoration: none;
  60.     display: inline-block;
  61.     font-size: 12px;
  62.     margin: 4px 2px;
  63.     cursor: pointer;
  64. }
  65.  
  66. .button1 {border-radius: 6px;}
  67. </style>
  68. <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
  69. </head>
  70. <body>
  71.  
  72. <!--<p> Test1: <button id="btnExport" onclick="javascript:xport.toXLS('testTable');"> Export to XLS</button> <em>&nbsp;&nbsp;&nbsp;Export the table to XLS with CSV fallback for IE & Edge</em>
  73.   </p>-->
  74. <p><button id="btnExport" onclick="javascript:xport.toCSV('testTable');" class="button button1"> Export to CSV</button></p>
  75. <br>
  76. <page size="A4">
  77. <table id="testTable" rules="groups" frame="hsides" border="1" style="margin-left:4%;" class="table table-striped">  
  78.   <thead valign="top">
  79.     <tbody valign="top">      
  80.     <tr>
  81.       <th></th>
  82.       <th colspan="7" style="font-weight: bold; padding: 5px;"> PT. Javis Teknologi Albarokah</th>
  83.     </tr>
  84.     <tr>
  85.       <th></th>
  86.       <th colspan="7" style="font-weight: bold; padding: 5px;"> Jl. Elang Jawa No.12, Yogyakarta</th>
  87.     </tr>
  88.     </tbody>
  89.     <tr><td></td></tr>
  90.     <tr>
  91.     <th></th>
  92.       <th colspan="7" style="font-weight: bold; padding: 5px;"> Purchase Order</th>
  93.     </tr>
  94.     <tr><td></td></tr>
  95.     <tbody>      
  96.     <tr>
  97.     <th></th>
  98.     <?php
  99.     $sql = "SELECT id_project, projectname, description, client, start, deadline FROM project WHERE id_project='$id_project'";
  100.     $result = $conn->query($sql);
  101.     foreach ($result as $value)
  102.     ?>
  103.      <th colspan="7" align="left" style="padding-bottom: 10px; padding-top: 10px; font-weight: bold;"> Nama Project : <?php echo $value['projectname']; ?></th>
  104.         </tr>
  105.         <tr>
  106.             <th></th>
  107.             <th colspan="7" align="left" style="padding-bottom: 10px; font-weight: bold;"> Kode Project : <?php echo $value['id_project']; ?></th>
  108.         </tr>
  109.         <tr>
  110.             <th></th>
  111.             <th colspan="7" align="left" style="padding-bottom: 10px; font-weight: bold;"> Deskripsi : <?php echo $value['description']; ?></th>
  112.         </tr>
  113.         <tr>
  114.             <th></th>
  115.             <th colspan="7" align="left" style="padding-bottom: 10px; font-weight: bold;"> Klien : <?php echo $value['client']; ?></th>
  116.         </tr>
  117.         <tr>
  118.             <th></th>
  119.             <th colspan="7" align="left" style="padding-bottom: 10px; font-weight: bold;"> Tanggal Mulai : <?php echo $value['start']; ?></th>
  120.         </tr>
  121.             <tr>
  122.             <th></th>
  123.             <th colspan="7" align="left" style="padding-bottom: 10px; font-weight: bold;"> Tanggal Akhir : <?php echo $value['deadline']; ?></th>
  124.         </tr>
  125.     </tbody>
  126.        
  127.     <?php
  128.         $result = mysqli_query($conn, "SELECT id_task FROM task WHERE id_project=$id_project"); $i=0;
  129.         $jumlahTask = mysqli_num_rows($result);
  130.         while($row = mysqli_fetch_assoc($result)){
  131.         $list[$i]=$row['id_task']; $i++;
  132.       }
  133.     for($i=0;$i<$jumlahTask;$i++){
  134.     $result = mysqli_query($conn, "SELECT taskname, taskto, FROM task WHERE a.id_task='$list[$i]'");
  135.     while($row = mysqli_fetch_assoc($result)){
  136.     echo"
  137.     <tbody>
  138.         <tr>
  139.             <th></th>
  140.             <th colspan='7' align='left' style='font-weight: bold;'> Item Pekerjaan : ".$row['taskname']." </th>
  141.         </tr>
  142.         <tr>
  143.             <th></th>
  144.             <th colspan='7' align='left' style='font-weight: bold;'> Divisi Penanggung Jawab : ".$row['taskto']."</th>
  145.         </tr>
  146.         <tr>
  147.             <td style='font-weight: bold; padding: 5px;'></td>
  148.         </tr>
  149.     </tbody>";
  150.    
  151.     $result2 = mysqli_query($conn, "SELECT a.id_order, a.part_order, a.qty_order, a.unit_order FROM orders a, task b WHERE a.id_task=b.id_task AND a.id_task=$list[$i]");
  152.     while($row2 = mysqli_fetch_assoc($result2)){
  153.     echo"
  154.     <tbody>
  155.         <tr>
  156.             <th></th>
  157.             <th></th>      
  158.             <th style='background-color: #2a3f54; color: #fff;' width='350px;'>Detail Item Pekerjaan</th>
  159.             <th align='right' style='background-color: #2a3f54; color: #fff;' width='50px;'>Qty</th>
  160.             <th align='right' style='background-color: #2a3f54; color: #fff;' width='80px;'>Satuan</th>
  161.             <th></th>
  162.             <th></th>    
  163.         </tr>
  164.     </tbody>
  165.        <tr>
  166.            <td></td>
  167.             <td></td>
  168.             <td>".$row2['part_order']."</td></td>
  169.             <td align='right'>".$row2['qty_order']."</td></td>
  170.             <td align='right'>".$row2['unit_order']."</td></td>
  171.             <td></td>
  172.             <td></td>            
  173.         </tr>";
  174.     }}}
  175.     ?>
  176. </table>
  177. <br>
  178. <br>
  179. </page>
  180. <script  src="js/excels.js"></script>
  181. <script src="js/jquery.min.js"></script>
  182. </body>
  183. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement