Advertisement
Guest User

Untitled

a guest
Apr 27th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.29 KB | None | 0 0
  1. <?php
  2.  
  3. $dbHost = 'localhost';
  4. $dbUsername = 'root';
  5. $dbPassword = '';
  6. $dbName = 'penyatakewangan';
  7. //Connect with the database
  8. $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
  9.  
  10. //Display error if failed to connect
  11. if ($db->connect_errno) {
  12.     printf("Connect failed: %s\n", $db->connect_error);
  13.     exit();
  14. }
  15.  
  16. $sql = "SELECT * FROM akaun where jenis = 1";
  17. $resultdebit = mysqli_query($db,$sql);
  18. $resultdebit2 = mysqli_query($db,$sql);
  19. $num1 = mysqli_num_rows($resultdebit);
  20.  
  21. $sql = "SELECT * FROM akaun where jenis = 2";
  22. $resultkredit = mysqli_query($db,$sql);
  23. $resultkredit2 = mysqli_query($db,$sql);
  24. $num2 = mysqli_num_rows($resultkredit);
  25. ?>
  26. <!doctype html>
  27. <html lang="en">
  28.   <head>
  29.     <!-- Required meta tags -->
  30.     <meta charset="utf-8">
  31.     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  32.  
  33.     <!-- Bootstrap CSS -->
  34.     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
  35.  
  36.     <title>Hello, world!</title>
  37.   </head>
  38.   <body>
  39.   <main class="container">
  40.     <h1>Penyata Kewangan</h1>
  41.     <table class="table">
  42.     <thead class="thead-light">
  43.         <tr>
  44.         <th colspan="3" class="text-center">Pendapatan</th>
  45.         <th colspan="3"  class="text-center">Perbelanjaan</th>
  46.         </tr>
  47.         <tr>
  48.         <th style="width: 5%">#</th>
  49.         <th style="width: 25%">Tajuk</th>
  50.         <th style="width: 10%">Debit</th>
  51.  
  52.         <th style="width: 5%">#</th>
  53.         <th style="width: 25%">Tajuk</th>
  54.         <th style="width: 10%">Kredit</th>
  55.         </tr>
  56.     </thead>
  57.     <tbody>
  58.        
  59.         <tr>
  60.         <th ><?php for($v1 =1;$v1<=$num1;$v1++) echo $v1.'</br>';?></th>
  61.            
  62.         <td><?php while($debit = mysqli_fetch_assoc($resultdebit)){?> <?=$debit['tajuk']?></br> <?php }?></td>
  63.         <td><?php $jumdebit = 0; while($debitt = mysqli_fetch_assoc($resultdebit2)){?> <?=$debitt['jumlah']?></br> <?php $jumdebit+=$debitt['jumlah']; }?></td>
  64.          
  65.         <th ><?php for($v2 =1;$v2<=$num2;$v2++) echo $v2.'</br>';?></th>
  66.         <td><?php while($kredit = mysqli_fetch_assoc($resultkredit)){?> <?=$kredit['tajuk']?></br> <?php $v2++;}?></br></td>
  67.         <td><?php $jumkredit = 0; while($kreditt = mysqli_fetch_assoc($resultkredit2)){?> <?=$kreditt['jumlah']?></br> <?php $jumkredit+=$kreditt['jumlah']; }?></td>
  68.        
  69.         </tr>
  70.        
  71.         <?php
  72.         if($jumdebit > $jumkredit){
  73.              $untung = $jumdebit - $jumkredit;
  74.              $inUntung =$untung ;
  75.              $varuntung = 'Untung Bersih';
  76.              $varugi = '';
  77.              $indRugi = '';
  78.         }else  {
  79.             $rugi = $jumkredit - $jumdebit;
  80.             $varuntung = '';
  81.              $varugi = 'Rugi Bersih';
  82.             $inUntung ='' ;
  83.             $indRugi = $rugi;
  84.         }
  85.         ?>
  86.         <tr>
  87.         <td colspan="1"></td>
  88.         <td >Untung Kasar</td>
  89.         <td ><?=$jumdebit?></td>
  90.  
  91.         <td colspan="1"></td>
  92.         <td >Rugi Kasar</td>
  93.         <td ><?=$jumkredit?></td>
  94.         </tr>
  95.        
  96.         <tr class="bg-light">
  97.         <td colspan="1"></td>
  98.         <td ><strong><?=$varuntung?></strong></td>
  99.         <td ><strong><?=$inUntung?></strong></td>
  100.  
  101.         <td colspan="1"></td>
  102.         <td ><strong><?=$varugi?></strong></td>
  103.         <td ><strong><?=$indRugi?></strong></td>
  104.         </tr>
  105.  
  106.         <tr >
  107.         <td colspan="6"></td>
  108.         </tr>
  109.     </tbody>
  110.     </table>
  111.  
  112.  
  113.   </main>
  114.     <!-- Optional JavaScript -->
  115.     <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  116.     <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  117.     <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
  118.     <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
  119.   </body>
  120. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement