Advertisement
noam76

form with dropdown list.php

Apr 17th, 2020
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.75 KB | None | 0 0
  1. <?php
  2. header('Content-Type: text/html; charset=utf-8');
  3. include("con.php"); //insert data server
  4.  
  5. try {
  6.    // read from products table
  7.    $sth = $pdo->prepare("SELECT product_name, product_number FROM products ORDER BY product_name ASC");
  8.    $sth->execute();
  9.    $results = $sth->fetchAll(PDO::FETCH_ASSOC);
  10.    }
  11. catch(Exception $e){
  12.   $pdo->rollBack();
  13.   echo "<br>" . 'N° : '.$e->getCode();
  14.   echo "<br>" . 'Error : '.$e->getMessage();
  15.   $pdo = null;
  16. }
  17. ?>
  18.  
  19. <!DOCTYPE html>
  20. <html lang="he">
  21. <head>
  22.   <meta charset="UTF-8">
  23.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  24.   <link rel = "stylesheet" type = "text/css" href = "myStyle.css"/>
  25.   <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  26.   <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  27.   <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  28.   <title>הצג מלאי</title>
  29. </head>
  30. <body>
  31.  
  32. <form action="" method="POST" class="form-style-9">
  33. <div align="right">
  34.  <H1 align="right">בחר מוצר מהרשימה</H1>
  35.  <ul>
  36.   <li>
  37.     <!-- שם מוצר ושמירת המספר -->
  38.     <?php
  39.     echo "<label for='product_number'><select class='field-style field-split align-left' name='product_number' id='product_number_select' onChange='outputValue(this)'>";
  40.     echo "<option>בחר מוצר:</option>";
  41.     foreach($results as $row)
  42.     {
  43.       echo "<option value='" . $row['product_number'] . "'>" . $row['product_name'] . "</option>";
  44.     }
  45.     echo "</select></label>";
  46.     echo "<input type='hidden' id='output' name='output' readonly/>";
  47.     ?>
  48.   </li>
  49.   <li>
  50.     <input type="submit" value="הצג מוצר" style = "font-size:20px; float:right">
  51.   </li>
  52.  </ul>
  53.  </div>
  54.  </form>
  55.  
  56.  <?php
  57.  try {
  58.    if($_SERVER['REQUEST_METHOD'] == 'POST') {
  59.     $product_number = $_POST['output'];
  60.     if(empty($product_number)) {
  61.      ?>
  62.       <div id="dialog-message" title="שגיאה">
  63.        <p align="right">
  64.         <span class="ui-icon ui-icon-circle-close" style="float:right; margin:0 7px 50px 0;"></span>
  65.          יש למלא את כל השדות
  66.        </p>
  67.       </div>
  68.       <?php
  69.     }
  70.     else {
  71. /*   
  72.      $firstname = "";
  73.      $lastname = "";
  74.      $sth = $pdo->query("SELECT DISTINCT products.product_name, products.product_number, products.IDCategorie FROM inventory_stock
  75.   INNER JOIN products ON inventory_stock.product_number = products.product_number WHERE products.product_number = $product_number");
  76.     $sth->setFetchMode(PDO::FETCH_BOTH);// Mode par défaut (tableau)
  77.       while($row = $sth->fetch())
  78.        {
  79.         $firstname = $row['product_name'] ;
  80.         $lastname = $row['product_number'] ;
  81.        }
  82.        echo "<table>
  83.              <tr class='noborder'>
  84.              <td><FONT SIZE=25>דף חשבון של ", $firstname, '&nbsp', $lastname,"</FONT></td></tr>
  85.              </table><br><br>";
  86. */
  87.     // read product name from a specific product
  88.     $prod = $pdo->prepare("SELECT product_name FROM products WHERE product_number = :product_number");
  89.     $prod->bindValue(':product_number', $product_number);
  90.     $prod->execute();
  91.     $row = $prod->fetch(PDO::FETCH_ASSOC);
  92.     $product_name = $row['product_name'];
  93.     // echo $row['product_name'];
  94.    
  95.     // read sum total input from a specific product
  96.     $sum = $pdo->prepare("SELECT SUM(amount_in) AS 'Total_Input' FROM inventory_stock WHERE product_number = :product_number");
  97.     $sum->bindValue(':product_number', $product_number);
  98.     $sum->execute();
  99.     $row = $sum->fetch(PDO::FETCH_ASSOC);
  100.     $total_in = $row['Total_Input'];
  101.     // echo $row['Total_Input'];
  102.    
  103.     // read sum total output from a specific product
  104.     $sum = $pdo->prepare("SELECT SUM(amount_out) AS 'Total_Output' FROM inventory_stock WHERE product_number = :product_number");
  105.     $sum->bindValue(':product_number', $product_number);
  106.     $sum->execute();
  107.     $row = $sum->fetch(PDO::FETCH_ASSOC);
  108.     $total_out = $row['Total_Output'];
  109.     // echo $row['Total_Output'];
  110.    
  111.     $total = $total_in - $total_out;
  112.     $total = max($total, 0);
  113.        
  114.  echo "
  115.       <table class='tutorial-table' align='center';>
  116.       <tr>
  117.        <th>סהכ כמות במלאי</th>
  118.        <th>מקט</th>
  119.        <th>שם המוצר</th>
  120.        </tr>
  121.       <tr>
  122.        <td>$total</td>
  123.        <td>$product_number</td>
  124.        <td>$product_name</td>
  125.       </tr>
  126.       </table>
  127.        ";
  128.        /* '&#8362;', */
  129.    }
  130.   }
  131.  }
  132.  
  133.  catch(Exception $e){
  134.    echo "<br>" . 'N° : '.$e->getCode();
  135.    echo "<br>" . 'Error : '.$e->getMessage();
  136.    $pdo = null;
  137.  }
  138.  ?>
  139. </body>
  140. </html>
  141. <script>
  142. function outputValue(item)
  143. {
  144.  document.getElementById('output').value = item.value;
  145. }
  146.  
  147. $( function(){
  148.   $( "#dialog-message" ).dialog({
  149.     modal: true,
  150.     buttons: {
  151.      Ok: function() {
  152.       $( this ).dialog( "close" );
  153.      }
  154.     }
  155.   });
  156. });
  157. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement