Jump to content

populating dynamic input rows based on dynamic drop down listmenu for sending t


Recommended Posts

Hello Fellows... i have this project am working on which i wrote a code to which you can specify the number of input fields you want to use, say 4 then the resulting input fields will be laid out in 4 rows. now the first input in each of the rows is dynamic from mysql database which when you select coca cola, the corresponding input fields against it will display quantity, price and amount from the database... this is working but half way in that when you select an item, the corresponding qty, price and amount will display but when i select a second item on a different row, instead of displaying the corresponding qty, price and amount in the inputs in the present row, it rather updates the first row and displays only amount. i have pasted the code below... can any good developer pls help me out by restructuring this to the desired working condition for me... ur help will be highly appreciated... thanks... Mr.Heart5000

 

<?php 
   include('../system/config.php');
   include('../system/sql.inc.php');
   
      session_start();
      $_SESSION["role"] = "acc/staff";
      $myname = $_SESSION["username"];
      secure($_SESSION["username"]);
   $catt = ("SELECT * FROM `category` WHERE (`branchcode` = '{$_SESSION["branchcode"]}') AND (`code`=50455)");
   //   $co = ("select `code` from `category` where 
      $categ= myQ($catt);
      $proj = myQ("SELECT * FROM `project` WHERE `branchcode` = '{$_SESSION["branchcode"]}'");   
      $transtype = myQ("SELECT * FROM `transactiontypes`");
      
      
      
                  $old = $newitem['qtyleft'][$key];
                  echo $old;
      
      
      $user = myF(myQ("SELECT `fname`,`lname`,`username`, `pass` FROM `staffsales` WHERE (LCASE(`username`) = '$myname');"));
      
      
      
          if (array_key_exists("Submit",$_POST)){
         
         $transID         = check(4);
         $projectcode     = $_POST["pcode"];
         $category        = $_POST["category"];
         $trans_code      = $_POST["transtype"];
         $admin           = "ceo";
         $name            = $user["fname"]." ".$user["lname"];
         $item            = $_POST["item"];
         $qty             = $_POST["qty"];
         $unit_price      = $_POST["uprice"];
         $amount          = $_POST["Gtotal"];
         $remark          = $_POST["rem"];
         $approval_status = "pending";
         $dotransaction   = date('y/m/d h:i');
         
        //$cname           = categoryQl($_POST['category'],"category");
           
         foreach ($_POST["item"] as $key => $val) {   
                                 
                     if (isset($_POST["item"]) && trim($_POST["item"])!= ""){
                     if(isset($_POST["item"][$key]) && trim($_POST["item"][$key])!= ""){
                  
                  $qt = $_POST["qty"][$key];
                  $search = $_POST["item"][$key];
                  
                  
                  //echo $qtyleft;
                   //echo $qtyleft;
                  //echo $qt;
                  //echo $search;
                  //echo $_POST["item"];
                  //$newitem = myQ("UPDATE `item` SET qtyleft = $newqty WHERE item_id = '$qtyleft'");
                  
                  $old = $newitem['qtyleft'][$key];
                  
                  //echo $old;
                  
                  
                     $sql=myQ("INSERT INTO  `store_batch`(`transID`,`projectcode`,`category`,
                           `trans_code`,`trans_done_by`,`approved_by`,`item`,                                                      
                           `qty`,`unit_price`,`amount`,`remark`, `approval_status`, `grand_total`, `trans_date`)
                            
                            VALUES(
                                        '$transID',
                                        '$projectcode',
                                        '$category ',
                                        '$trans_code ',
                                        '$name',
                                        '$admin',
                                                                                
                                        '".((isset($_POST["item"][$key]) && $_POST["item"][$key] != "") ? 
                                          $_POST["item"][$key] :"N/A")."',
                                           
                                        '".((isset($_POST["qty"][$key]) && $_POST["qty"][$key] != "") ? 
                                           $_POST["qty"][$key] :"N/A")."',
                                           
                                        '".((isset($_POST["uprice"][$key]) && $_POST["uprice"][$key] != "") ? 
                                           $_POST["uprice"][$key] :"N/A")."',
                                          
                                        '".((isset($_POST["amount"][$key]) && $_POST["amount"][$key] != "") ? 
                                           $_POST["amount"][$key] :"N/A")."',
                                                                                 
                                        '".((isset($_POST["rem"][$key]) && $_POST["rem"][$key] != "") ? 
                                           $_POST["rem"][$key] :"N/A")."',
                                           
                                        '$approval_status',
                                        '$amount',
                                        '$dotransaction');
                                        
                                    ") or die(mysql_error());
                                    $errMsg =  ($sql== 1) ? "<p><font color='green' size=1>Application Made Successfully! <b>
                                    with Application id = $transID</b></p></font>" : "<p><font color='red' size=1>An  
                                 error has occured while performing this operation. Please try again later</p></font>";
                              
                  }

            else
                 $errmsg="<span class=errormsg>Error:please select expense number</span>";
           
                                                                                    }  else
                                                                
                  $errmsg="<span class=errormsg>Error:please supply a valid input project</span>";    
                                                            }
               
                                                }
                                  
?>               
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<style type="text/css">
   body, th, td, p, small {
   font-size:12px; font-family:Verdana, Arial, Helvetica, sans-serif;
   margin:0; padding:0; font-style:normal; font-variant:normal; font-weight:normal; 
   line-height: 15px;
   }
   </style>
   <script type="text/javascript">
   </script>
    
<link type="text/css" rel="stylesheet" href="../css/jquery.ui.all.css" />
<script type="text/javascript"  src="../js/jquery-1.4.2.js"></script>
<script type="text/javascript" src="../js/jquery.ui.core.js"></script>
<script type="text/javascript" src="../js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="../js/jquery.ui.datepicker.js"></script>
<link type="text/css" href="../css/demos.css" rel="stylesheet" />
<script type="text/javascript">
   $(function() {
      $("#datepicker").datepicker();
      $("#format").change(function() { $('#datepicker').datepicker('option', {dateFormat: $(this      ).val()}); });
   });
   $(function() {
      $("#datepicker1").datepicker();
      $("#format").change(function() { $('#datepicker').datepicker('option', {dateFormat: $(this     ).val()}); });
   });
   </script>
    <script type="text/ecmascript"><table width="200" border="0">
  <tr>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
</table>

   function det(url_add)
   {
   window.open(url_add,'details','width=400,height=400,menubar=yes, status=yes, location=yes, toolbar=yes, scrollbars=yes, left=400');
   }
   
   </script>
   <?php if($_SESSION["is_logged"]){
       display($_SESSION["username"]); 
       displayA($_SESSION["branchcode"]);
             ?>
<body background="../../images/backgrnd.gif">
<form action="" method="post" enctype="multipart/form-data" name="itemf">
<div style="width:100%; margin:0 auto">
<fieldset style="width:400px">
<legend><strong>Apply For Stock Item</strong></legend>
<table width="647" border="0" align="center">
  <tr>
    <td colspan="5" style="text-decoration:blink;"><?php echo $errMsg ?><label></label></td>
    </tr>
  <tr>
    <td><label>Project Name: 
        
</label></td>
    <td width="184"><label>
      <select name="pcode" style="width:100px">
        <option value="">Select One</option>
        <?php
         while($pj = myF($proj)) {
         
      ?>
        
          }
          
          
        <option value="<?php echo $pj['projectcode']?>" <?php echo ($_POST['pcode'] == $pj['projectcode']) ? "selected" : "" ?>>          
      <?php echo $pj['projectname']?>
        </option>
        <?php }   
            ?>
      </select>
    </label></td>
    <td width="161" align="right">Operation: </td>
    <td width="156"><label>
    <select name="transtype" style="width:100px" id="transtype">
      <option value="">Select One</option>
      <?php
         while($tr = myF($transtype)) {
         
      ?>
      
        
          }
          
          
        
      <option value="<?php echo $tr['trans_id']?>" <?php echo ($_POST['transtype'] == $tr['trans_id']) ? "selected" : "" ?>> <?php echo $tr['trans_type']?> </option>
      <?php }   
            ?>
    </select>
    </label></td>
    <td width="31"> </td>
    </tr>
  <tr>
    <td><label>category
   </label></td>
    <td><label>
      <select name="category" style="width:140px" onchange="this.form.submit();">
        <?php
         while($ct = myF($categ)) {
         
      ?>
        <option value="<?php echo $ct['code']?>" <?php echo ($_POST['category'] == $ct['code']) ? "selected" : "" ?>> <?php echo $ct['category'] ?></option>
        <?php }   
            ?>
      </select>
    </label></td>
    <td align="right">No of Store Items:</td>
    <td><label>
      <select name="num" onchange="this.form.submit();" style="width:50px">
        <?php
           for ($i = 0; $i < 10; $i++) {
     ?>
        <option value="<?php echo $i ?>" <?php echo ($_POST["num"] == $i) ? "selected" : "" ?>><?php echo $i ?></option>
        <?php
          } 
     ?>
      </select>
    </label></td>
    <td><label></label></td>
    </tr>
</table>

</fieldset>
<div> </div>
   <?php 
      if (strlen($err)>0) { 
   ?>

<div><table cellpadding="0" cellspacing="3" align="center">
   <tr>
     <td><?php echo $err ?></td>
    </tr>
</table></div>

<?php 
   }
?>

<?php
   if (array_key_exists("num",$_POST)) {
      /*
         be sure there's need to provide description
      */
      if (intval($_POST["num"]) > 0) { 
?>
<div style="width:100%; margin:0 auto">

<fieldset style="width:400px">
<legend><strong>Stock Item Details</strong></legend>
<div align="left"><?php echo $errMsg1 ?></div>
<table width="471" border="0" align="left">
  <tr>
    <td width="52"><div align="center"></div></td>
    <td width="200"> </td>
    <td width="102"> </td>
    <td width="99"> </td>
  </tr>
  <tr bgcolor="#CCCCCC">
    <td><div align="center"><strong>S/No</strong></div></td>
    <td><div align="center"><strong>Item Description</strong></div></td>
    <td><div align="center"><strong>Quantity</strong></div></td>
    <td><div align="center"><strong>Unit Price</strong></div></td>
    <td><div align="center"><strong>Amount</strong></div></td>
    <td><div align="center"><strong>Remark</strong></div></td>
  </tr>
  <?php
        $k = 0;
      $T_amount = 0;
      while ($k < intval($_POST["num"])) {
        $T_amount+=($_POST["amount"][$k]);
         $k++;
  ?>   
  <tr class="<?php echo $k%2==0?"odd":"even" ?>">
  
    <td><?php echo $k ?></td>
    <td><div align="justify">
    
    <select name="item[]" id="item" onchange="document.getElementById('uprice').value=this[this.selectedIndex].value">
    <option value="">Select One</option>
    <?
   $items = myQ("SELECT * FROM `item` WHERE (`branchcode` = '{$_SESSION["branchcode"]}')");
    while($shima = myF($items)){
   ?>
      <option value="<? $shima['item_id']; ?> <? echo $shima['item_id'];?>">
     <? echo $shima['item_desc']; ?>
      </option>echo $shima['item_id'];
      <? }?>
      
    </select>
    </div></td>
    <td><input type="text" name="qty[]"    id="qty[]"    style="width:100px" onkeyup="document.getElementById('amount').value=this[this.selectedIndex].value*document.getElementById('uprice').value"></td>
    <td><input type="text" name="uprice[]" id="uprice" style="width:100px"></td>
    <td><input type="text" name="amount[]" id="amount" style="width:100px"></td>
    <td><input type="text" name="rem[]"    id="rem" style="width:100px"></td>
    <td><input type="hidden" name="qtyleft[]"    id="qtyleft"></td>
    
    
   </tr>
   <?php
   }
      
   ?>
  <tr class="">
    <td colspan="2"><div align="right"><strong>GRAND TOTAL:</strong></div></td>
    <td><label>
      <input type="text" name="Gtotal" style="width:100px" value="<?php echo $T_amount.'.00';?>" />
    </label></td>
    <td> </td>
  </tr>
   <tr>
       <td colspan="5"><input type="submit" name="Submit" value="Request Now" /></td>
        
    </tr>
</table>

</fieldset>
<?php
      //echo $_POST["qty"][$key];   
       //echo $shima['qtyleft'][$key];
       //echo $_POST['item'][$key];
           //echo $_POST['qtyleft'][$key];
       //echo $_POST['item'];
       //$kk = "SELECT * FROM item WHERE item_id = '$search'"";
             
         }
         
      }
                  $qtyleft = $_POST['qtyleft'][$key];
                  $_SESSION["qt"] = $qtyleft;
                  $search = $_POST["item"][$key];
                  $_SESSION['search'] = $search;
                   //echo $qtyleft;
                  $try = $_POST["qty"][$key];
                  //echo $try;
                  $new = $old-$try;
                  
                  
                     
                  $qtyleft = $_POST['qtyleft'][$key];
                  myQ("UPDATE item SET `qtyleft` = (qtyleft-'$try') WHERE item_id='20004'");
                  
                  
      
?>
</form>
</body>
<? }else echo "you're not granted privileges to this page"?>
</html>
<script language="javascript">
function up2(){
     
  document.getElementById("qtyleft").value = this[this.selectedIndex].value
}
</script>

 

MOD EDIT: code tags added.

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.