noam76 icon

form with dropdown list.php

noam76 | PRO | 04/17/20 10:56:48 AM UTC | 0 ⭐ | 741 👁️ | Never ⏰ | []
PHP |

4.75 KB

|

None

|

0 👍

/

0 👎

<?php 
header('Content-Type: text/html; charset=utf-8');
include("con.php"); //insert data server
 
try {
   // read from products table
   $sth = $pdo->prepare("SELECT product_name, product_number FROM products ORDER BY product_name ASC");
   $sth->execute();
   $results = $sth->fetchAll(PDO::FETCH_ASSOC);
   }
catch(Exception $e){
  $pdo->rollBack();
  echo "<br>" . 'N° : '.$e->getCode();
  echo "<br>" . 'Error : '.$e->getMessage();
  $pdo = null;
}
?>
 
<!DOCTYPE html>
<html lang="he">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel = "stylesheet" type = "text/css" href = "myStyle.css"/>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <title>הצג מלאי</title>
</head>
<body>
 
<form action="" method="POST" class="form-style-9">
<div align="right">
 <H1 align="right">בחר מוצר מהרשימה</H1>
 <ul>
  <li>
    <!-- שם מוצר ושמירת המספר -->
    <?php
    echo "<label for='product_number'><select class='field-style field-split align-left' name='product_number' id='product_number_select' onChange='outputValue(this)'>";
    echo "<option>בחר מוצר:</option>";
    foreach($results as $row) 
    {
      echo "<option value='" . $row['product_number'] . "'>" . $row['product_name'] . "</option>";
    }
    echo "</select></label>";
    echo "<input type='hidden' id='output' name='output' readonly/>";
    ?>
  </li>
  <li>
    <input type="submit" value="הצג מוצר" style = "font-size:20px; float:right">
  </li>
 </ul>
 </div>
 </form>
 
 <?php
 try {
   if($_SERVER['REQUEST_METHOD'] == 'POST') {
    $product_number = $_POST['output'];
    if(empty($product_number)) {
     ?>
      <div id="dialog-message" title="שגיאה">
       <p align="right">
        <span class="ui-icon ui-icon-circle-close" style="float:right; margin:0 7px 50px 0;"></span>
         יש למלא את כל השדות
       </p>
      </div>
      <?php 
    }
    else {
/*   
     $firstname = "";
     $lastname = "";
     $sth = $pdo->query("SELECT DISTINCT products.product_name, products.product_number, products.IDCategorie FROM inventory_stock 
  INNER JOIN products ON inventory_stock.product_number = products.product_number WHERE products.product_number = $product_number");
    $sth->setFetchMode(PDO::FETCH_BOTH);// Mode par défaut (tableau)
      while($row = $sth->fetch())
       {
        $firstname = $row['product_name'] ;
        $lastname = $row['product_number'] ;
       }
       echo "<table>
             <tr class='noborder'>
             <td><FONT SIZE=25>דף חשבון של ", $firstname, '&nbsp', $lastname,"</FONT></td></tr>
             </table><br><br>";
*/
    // read product name from a specific product
    $prod = $pdo->prepare("SELECT product_name FROM products WHERE product_number = :product_number");
    $prod->bindValue(':product_number', $product_number);
    $prod->execute();
    $row = $prod->fetch(PDO::FETCH_ASSOC);
    $product_name = $row['product_name'];
    // echo $row['product_name'];
    
    // read sum total input from a specific product
    $sum = $pdo->prepare("SELECT SUM(amount_in) AS 'Total_Input' FROM inventory_stock WHERE product_number = :product_number");
    $sum->bindValue(':product_number', $product_number);
    $sum->execute();
    $row = $sum->fetch(PDO::FETCH_ASSOC);
    $total_in = $row['Total_Input'];
    // echo $row['Total_Input'];
    
    // read sum total output from a specific product
    $sum = $pdo->prepare("SELECT SUM(amount_out) AS 'Total_Output' FROM inventory_stock WHERE product_number = :product_number");
    $sum->bindValue(':product_number', $product_number);
    $sum->execute();
    $row = $sum->fetch(PDO::FETCH_ASSOC);
    $total_out = $row['Total_Output'];
    // echo $row['Total_Output'];
    
    $total = $total_in - $total_out;
    $total = max($total, 0);
        
 echo "
       <table class='tutorial-table' align='center';>
       <tr>
       <th>סהכ כמות במלאי</th>
       <th>מקט</th>
       <th>שם המוצר</th>
       </tr>
       <tr>
       <td>$total</td>
       <td>$product_number</td>
       <td>$product_name</td>
       </tr>
       </table>
       ";
       /* '&#8362;', */
   }
  }
 }
 
 catch(Exception $e){
   echo "<br>" . 'N° : '.$e->getCode();
   echo "<br>" . 'Error : '.$e->getMessage();
   $pdo = null;
 }
 ?> 
</body> 
</html>
<script>
function outputValue(item)
{
 document.getElementById('output').value = item.value;
}
 
$( function(){
  $( "#dialog-message" ).dialog({
    modal: true,
    buttons: {
     Ok: function() {
      $( this ).dialog( "close" );
     }
    }
  });
});
</script>

Comments