Problem in Subtraction

Discussion in 'PHP' started by newphpcoder, Dec 9, 2010.

  1. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines
    Good day!
    I need to automatically subtract the input qty and output qty and the result should be appear in the text area of qty.
    the input qty and output qty depend on the operation name.
    i try this code:
    PHP:
    <?php
      
    include("config.php");
      
      
    $query "SELECT operation_name FROM clt_traceability WHERE operation_name = '01. Spreading'";
      
      
    $inqty $_POST['input_qty'];
      
    $outqty $_POST['output_qty'];
      
    $qty $_POST['variance_qty'];
      
      
    $qty $inqty $outqty;
      
    ?>
    <html>
    <body>
    Input<input type = 'text' name='inqty' id='inqty' />
    Output<input type = 'text' name='outqty' id='outqty' />
    Qty<input type = 'text' name='qty' id='qty' />
    </body>
    </hmtl> 
    in this code when i enter input = 100 output= 50 and when I enter or I used tab no output in qty.
    Thank you..
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    First you have to understand the difference between PHP and HTML.

    PHP is server side and HTML is client side.

    You are calculating when you post in server side but in your HTML you missed the submit button and so that calculation is never executed.

    Again you are calculating in variables which are never displayed in HTML and so again if calculation happens then also your values will not show in the output field.
     
  3. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines

    I revised my code:
    PHP:
    <?php
      
    include("config.php");
      
      
    $query "SELECT operation_name FROM clt_traceability WHERE operation_name = '01. Spreading'";
      
    $result mysql_query($query);
      
      if (
    mysql_fetch_row($result))
      {     
      
    $inqty $_POST['input_qty'];
      
    $outqty $_POST['output_qty'];
      
    $qty $_POST['variance_qty'];
      
      
    $qty $inqty $outqty;
      }
      
    ?>
    <html>
    <head>
     <script language="javascript">
        function handleEnter(e, nextfield)
            {
            var characterCode = (e && e.which)? e.which: e.keyCode;
            if(characterCode == 13)
                {
                document.getElementById(nextfield).focus();
                return false;
                } 
            else
                {
                return true;
                }
            }
        </script>
    </head>
    <body>
    <form action="qty.php" method="post" name="qty">
    <?php
    echo "Input:<input type='text' name='inqty' id='inqty'onkeypress='return handleEnter(event,\"outqty\");' /><br />";
    echo 
    "Output:<input type='text' name='outqty' id='outqty'onkeypress='return handleEnter(event,\"qty\");' /><br />";
    echo 
    "Qty:<input type='text' name='qty' id='qty'onkeypress='return handleEnter(event,\"saveform0\");' /><br />";
    echo 
    "<p><input type='submit' value='  Save  ' id='saveform' /></p>";
    ?>
    </form>
    </body>
    </hmtl>
    Stil the qty was not appear.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Still you are not submitting the form buddy.
     
  5. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines
    How can I submit?
     
  6. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines
    As I've on my first thread, that code is for testing purposes only. Now I will post the real code of my webpage which I need to add code for subtracting input qty and output qty and the result is automatically display in qty text field.
    PHP:
    <?php
    include("config.php");
    $rexist 0;
    if(
    $_POST["no"])
        {
        
    $clt_date $_POST["date"];
        
    $query "INSERT INTO clt (no, ac2l, b3, type, roll, t_date, date) VALUES ('" $_POST["no"] . "', '" $_POST["ac2l"] . "', '" $_POST["b3"] . "', '" $_POST["type"] . "', '" $_POST["roll"] . "', now(), '" $date "')";
        
    $result mysql_query($query);
        
    $transact_id mysql_insert_id();
        
        
    $opname $_POST["opname"];
        
    $timein $_POST["timein"];
        
    $timeout $_POST["timeout"];
        
    $inqty $_POST["inqty"];
        
    $iun $_POST["iun"];
        
    $outqty $_POST["outqty"];
        
    $oun $_POST["oun"];
        
    $idno $_POST["idno"];
        
    $mcno $_POST["mcno"];
        
    $varqty $_POST["varqty"];
        
    $varsublot $_POST["varsublot"];
        
    $dateshift $_POST["dateshift"];
        
    $shift $_POST["shift"];
        
        
    $totalarr count($opname) - 1;
        for(
    $ctr=0$ctr $totalarr$ctr++)
            {
            
    $inqty[$ctr] = (float) $inqty[$ctr];
            
    $varqty[$ctr] = (float) $varqty[$ctr];
            
    $outqty[$ctr] = (float) $outqty[$ctr];
            
    $query "INSERT INTO traceability (operation_name, time_in, time_out, input_qty, input_unit, output_qty, output_unit, id_no, mc_no, variance_qty, variance_sublot, date, shift, transact_id) VALUES ('" $opname[$ctr] . "', '" $timein[$ctr] . "', '" $timeout[$ctr] . "', '" $inqty[$ctr] . "' , '" $iun[$ctr] . "' ,'" $outqty[$ctr] . "', '" $oun[$ctr] . "' , '" $idno[$ctr] . "', '" $mcno[$ctr] . "', '" $varqty[$ctr] . "', '" $varsublot[$ctr] . "', '" $dateshift[$ctr] . "', '" $shift[$ctr] . "', '" $transact_id "')";
            
    $result mysql_query($query);
            
            }   
        }
    $rexist 0;
    ?>
    <html>
    <head>
        <script language="javascript">
        function handleEnter(e, nextfield)
            {
            var characterCode = (e && e.which)? e.which: e.keyCode;
            if(characterCode == 13)
                {
                document.getElementById(nextfield).focus();
                return false;
                } 
            else
                {
                return true;
                }
            }
        </script>
    </head>
    <body onLoad="document.type.no.focus();">
    <!--<p><a href="definition.php">Types</a><a href="query.php">Query</a></p>-->
    <?php
    include("menu.php");
    ?>
    <form action="main.php" method="post" name="type">
    <?php
        $rexist 
    1;
        echo 
    "<p>No:<input type='text' name='_no' onkeypress='return handleEnter(event,\"date\");' /><br />";
        echo 
    "Date:;<input type='text' name='date' onkeypress='return handleEnter(event,\"ac2l\");' /></p>";
        
        echo 
    "<table>";
        echo 
    "<tr><th class='myclass'>TRACEABILITY</th><th class='myclass'>LOT #</th></tr>";
        echo 
    "<tr><td>AC2L</td><td><input type='text' name='ac2l' id='ac2l' onkeypress='return handleEnter(event,\"b3\");' /></td></tr>";
        echo 
    "<tr><td>B3</td><td><input type='text' name='b3' id='b3' onkeypress='return handleEnter(event,\"type\");' /></td></tr>";
        echo 
    "<tr><td>Type</td><td><input type='text' name='type' id='type' onkeypress='return handleEnter(event,\"roll\");' /></td></tr>";
        echo 
    "<tr><td>Roll</td><td><input type='text' name='roll' id='roll' onkeypress='return handleEnter(event,\"timein0\");' /></td></tr>";
        echo 
    "</table>";
        echo 
    "<p>&nbsp;</p>";
        
        
    $query "SELECT * FROM trace_operations ORDER BY operation_name";
        
    $last_operation_name "";
        
    $result mysql_query($query);
        if(
    $result)
            {
            
    $rexist 1;
            echo 
    "<p><center><b>TRACEABILITY</center></b></p>";
            echo 
    "<table>";
            echo 
    "<tr><th class='myclass'>OPERATIONS</th><th class='myclass'>Time IN</th><th class='myclass'>Time OUT</th><th class='myclass'>INPUT <br/> QTY</th><th class='myclass'>UNIT</th><th class='myclass'>OUTPUT QTY</th><th class='myclass'>UNIT</th><th class='myclass'>NAME & ID #</th><th class='myclass'>MC #</th><th class='myclass'>VARIANCE Qty</th><th class='myclass'>VARIANCE Sub Lot</th><th class='myclass'>DATE</th><th class='myclass'>SHIFT</th></tr>";
            
    $totalrows mysql_num_rows($result);
            
    $trows $totalrows 1;
            for(
    $ctr 0$ctr $trows$ctr++)
                {
                
    $row mysql_fetch_array($result);
                
    $tctr $ctr 1;
                echo 
    "\n\t<tr>";
                echo 
    "\n\t\t<td>";
                if (
    $last_operation_name != $row["operation_name"]) echo $row["operation_name"];
                
    $last_operation_name $row["operation_name"];
                echo 
    "<input type='hidden' name='opname[]' value='" $row["operation_name"] . "' /></td>";   
                echo 
    "\n\t\t<td><input type='text' name='timein[]' id='timein" $ctr "' onkeypress='return handleEnter(event,\"timeout" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td><input type='text' name='timeout[]' id='timeout" $ctr "' onkeypress='return handleEnter(event,\"inqty" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td><input type='text' name='inqty[]' id='inqty" $ctr "' onkeypress='return handleEnter(event,\"outqty" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td>" $row["input_unit"];
                echo 
    "<input type='hidden' name='iun[]' value='" $row["input_unit"] . "' /></td>";
                echo 
    "\n\t\t<td><input type='text' name='outqty[]' id='outqty" $ctr "' onkeypress='return handleEnter(event,\"idno" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td>" $row["output_unit"];
                echo 
    "<input type='hidden' name='oun[]' value='" $row["output_unit"] . "'></td>";
                echo 
    "\n\t\t<td><input type='text' name='idno[]' id='idno" $ctr "' onkeypress='return handleEnter(event,\"mcno" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td><input type='text' name='mcno[]' id='mcno" $ctr "' onkeypress='return handleEnter(event,\"varqty" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td><input type='text' name='varsublot[]' id='varsublot" $ctr "' onkeypress='return handleEnter(event,\"dateshift" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td><input type='text' name='dateshift[]' id='dateshift" $ctr "' onkeypress='return handleEnter(event,\"shift" $ctr "\");' /></td>";
               echo 
    "\n\t\t<td><input type='text' name='shift[]' id='shift" $ctr "' onkeypress='return handleEnter(event,\"timein" $tctr "\");' /></td>";
                echo 
    "\n\t</tr>";
                }
            if(
    $totalrows 1);
                {
                
    $row mysql_fetch_array($result);
                echo 
    "\n\t<tr>";
                echo 
    "\n\t\t<td>";
                if (
    $last_operation_name != $row["operation_name"]) echo $row["operation_name"];
                
    $last_operation_name $row["operation_name"];
                echo 
    "<input type='hidden'  name='opname[]' value='" $row["operation_name"] . "' /></td>";   
                echo 
    "<input type='hidden' name='opname[]' value='" $row["operation_name"] . "' /></td>";
                echo 
    "\n\t\t<td><input  type='text' name='timein[]' id='timein" $ctr "' onkeypress='return handleEnter(event,\"timeout" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td><input  type='text' name='timeout[]' id='timeout" $ctr "' onkeypress='return handleEnter(event,\"inqty" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td><input  type='text' name='inqty[]' id='inqty" $ctr "' onkeypress='return handleEnter(event,\"outqty" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td>" $row["input_unit"];
                echo 
    "<input type='hidden' name='iun[]' value='" $row["input_unit"] . "' /></td>";
                echo 
    "\n\t\t<td><input  type='text' name='outqty[]' id='outqty" $ctr "' onkeypress='return handleEnter(event,\"idno" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td>" $row["output_unit"];
                echo 
    "<input type='hidden' name='oun[]' value='" $row["output_unit"] . "'></td>";
                echo 
    "\n\t\t<td><input  type='text' name='idno[]' id='idno" $ctr "' onkeypress='return handleEnter(event,\"mcno" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td><input type='text' name='mcno[]' id='mcno" $ctr "' onkeypress='return handleEnter(event,\"varqty" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td><input type='text' name='varqty[]' id='varqty" $ctr "' onkeypress='return handleEnter(event,\"varsublot" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td><input type='text' name='varsublot[]' id='varsublot" $ctr "' onkeypress='return handleEnter(event,\"dateshift" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td><input type='text' name='dateshift[]' id='dateshift" $ctr "' onkeypress='return handleEnter(event,\"shift" $ctr "\");' /></td>";
                echo 
    "\n\t\t<td><input type='text' name='shift[]' id='shift" $ctr "' onkeypress='return handleEnter(event,\"saveform\");' /></td>";
                echo 
    "\n\t</tr>";
                }
            echo 
    "</table>";
            }
        echo 
    "<p><input type='submit' value='  Save  ' id='saveform' /></p>";
        echo 
    "<input type='hidden' name='typeno' value='" $_POST["typeno"] . "' />";
    ?>
    </form>
    </body>
    </html>
    I need to subtract input qty to output qty then the result is automatically display in qty text field, I want it to happen in the operation is 03. Spread and 03. Pack
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You are trying to subtract two numbers in PHP but this can simply be done in plain and simple HTML

    See

    Code:
    <INPUT TYPE="text" NAME="qty1" Value="">
    <INPUT TYPE="text" NAME="qty2" value="">
    <INPUT TYPE="text" NAME="res" value="">
    <INPUT TYPE="submit" onClick="res.value=qty1.value-qty2.value">
    
    Now I understand that you have some added things to be done in PHP and for that you have to use the POST to get the value, do the calc and then show again.
     
  8. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines

    this is the new test code:
    PHP:
    PHP Code:
    <?php
        
    include("config.php");
        
    $qty 0;
    if(
    $_POST['submit']){
    $inqty $_POST['inqty'];
    $outqty $_POST['outqty'];
    }  
    $qty $inqty $outqty;
    ?>
    <html>
    <head>
    <!-- <script language="javascript">
        function handleEnter(e, nextfield)
            {
            var characterCode = (e && e.which)? e.which: e.keyCode;
            if(characterCode == 13)
                {
                document.getElementById(nextfield).focus();
                return false;
                }
            else
                {
                return true;
                }
            }
        </script>
            -->
    </head>
    <body>
    <form action="qty.php" method="post" name="testqty">
    Input:<input type='text' name='inqty' id='inqty' />
    Output:<input type='text' name='outqty' id='outqty'/> <br>
    Qty:<input type='text' name='qty' id='qty' value = '<?php echo $qty?>' /><br>
    <input type='submit' value='save' name='submit' id='submit'>
    </form>
    </body>
    </hmtl> 
    In this code the qty was appear after I click the save button.
    I want to happen is After I input numbers in input qty I press the enter key then the cursor will be in the output qty then after i input numbers in output text filed and I press the enter key the result should be appear automatically without pressing the button.
    I try this code:
    PHP:
    PHP Code:
    <?php
        
    include("config.php");
        
    $qty 0;
    if(
    $_POST['qty']){
    $inqty $_POST['inqty'];
    $outqty $_POST['outqty'];
    }  
    $qty $inqty $outqty;
    ?>
    <html>
    <head>
    <!-- <script language="javascript">
        function handleEnter(e, nextfield)
            {
            var characterCode = (e && e.which)? e.which: e.keyCode;
            if(characterCode == 13)
                {
                document.getElementById(nextfield).focus();
                return false;
                }
            else
                {
                return true;
                }
            }
        </script>
            -->
    </head>
    <body>
    <form action="qty.php" method="post" name="testqty">
    <?php
    echo"Input:<input type='text' name='inqty' id='inqty' onkeypress='return handleEnter(event,\"outqty\");' />";
    echo
    "Output:<input type='text' name='outqty' id='outqty' onkeypress='return handleEnter(event,\"qty\");' /> <br>";
    echo 
    "Qty:<input type='text' name='qty' id='qty' value = '<?php echo $qty; ?>' onkeypress='return handleEnter(event,\"inqty\");' />";
    ?>
    </form>
    </body>
    </hmtl> 
    The output of this code is the value of the text field of qty was the <?php echo $qty; ?>
    Thank you
     
    Last edited: Dec 10, 2010
  9. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines
    i want to happen is after I enter numbers in input and output and I press enter the result would be show in qty eventhough the next to output is id#
     
    Last edited: Dec 10, 2010
  10. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines
    I revised my code:
    PHP:
    PHP Code:
    include(
    "config.php");
    ?>
    <html>
    <head>
    <!-- <script language="javascript">
        function handleEnter(e, nextfield)
            {
            var characterCode = (e && e.which)? e.which: e.keyCode;
            if(characterCode == 13)
                {
                document.getElementById(nextfield).focus();
                return false;
                }
            else
                {
                return true;
                }
            }
        </script>
            -->
            
    <script language="javascript" >
    var inqty = document.getElementById('inqty')
    var outqty = document.getElementById('outqty')
    myqty = inqty - outqty 
    document.form-name.myqty.value = myqty 
    </script>
    </head>
    <body>
    <form action="qty.php" method="post" name="form-name">
    Input:<input type='text' name='inqty' id='inqty' />
    Output:<input type='text' name='outqty' id='outqty'/> <br>
    Qty:<input type='text' name='myqty' id='myqty' /><br>
    </form>
    </body>
    </html> 
    And it did not work
     
  11. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    My Code works for you or not? If it works use that code and change the events when you want the result to appear.
     
  12. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines
    In the code:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    var subtract = function(c, b, output){
      output.value = c.value-b.value;
      
    }
    </script>
    <input type="text" id="c" value="0"/>-<input type="text" id="b" value="0"/>=<input type="text" id="a" value="0"/><br/>
    <input type="text" id="d" value="0" />
    <script type="text/javascript">
    document.getElementById('c').onmousedown = function(){
    subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d'));
    }
    document.getElementById('b').onmousedown = function(){
    subtract(document.getElementById('c'), document.getElementById('b'), document.getElementById('a'), document.getElementById('d'));
    }
    </script>
    </head>
    </html>
    
    how can i used it in php and also the onkeyenter because in my real webpage my code for input type is like this:
    PHP:
    echo "\n\t\t<td><input size='6' type='text' name='inqty[]' id='inqty" $ctr "' onkeypress='return handleEnter(event,\"outqty" $ctr "\");' /></td>";
    echo 
    "\n\t\t<td><input size='6' type='text' name='outqty[]' id='outqty" $ctr "' onkeypress='return handleEnter(event,\"idno" $ctr "\");' /></td>";
    echo 
    "\n\t\t<td><input size='6' type='text' name='varqty[]' id='varqty" $ctr "' onkeypress='return handleEnter(event,\"varsublot" $ctr "\");' /></td>";
    and 
    i have this code:
    </
    style>
        <
    script language="javascript">
        function 
    handleEnter(enextfield)
            {
            var 
    characterCode = (&& e.which)? e.whiche.keyCode;
            if(
    characterCode == 13)
                {
                
    document.getElementById(nextfield).focus();
                return 
    false;
                } 
            else
                {
                return 
    true;
                }
            }
        </
    script>
    I'm sorry, because I'm not good in codeing and analyzing..I really need to fix this problem..
    Thank you
     
  13. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    This is not the problem of coding. This is the problem with what PHP can do and cannot do and when.

    PHP is server side programming and if you want an answer in the user screen with some field calculation you don't need any PHP.

    See my code and that should do the job for you. All you have to do is make sure you make that code appear in the right event handler.
     
  14. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines
    but my real code is almost pure php code:

    here it is:
    PHP:
    <?php 
    include("config.php"); 
    $rexist 0
    if(
    $_POST["no"]) 
        { 
        
    $clt_date $_POST["date"]; 
        
    $query "INSERT INTO clt (no, ac2l, b3, type, roll, t_date, date) VALUES ('" $_POST["no"] . "', '" $_POST["ac2l"] . "', '" $_POST["b3"] . "', '" $_POST["type"] . "', '" $_POST["roll"] . "', now(), '" $date "')"
        
    $result mysql_query($query); 
        
    $transact_id mysql_insert_id(); 
         
        
    $opname $_POST["opname"]; 
        
    $timein $_POST["timein"]; 
        
    $timeout $_POST["timeout"]; 
        
    $inqty $_POST["inqty"]; 
        
    $iun $_POST["iun"]; 
        
    $outqty $_POST["outqty"]; 
        
    $oun $_POST["oun"]; 
        
    $idno $_POST["idno"]; 
        
    $mcno $_POST["mcno"]; 
        
    $varqty $_POST["varqty"]; 
        
    $varsublot $_POST["varsublot"]; 
        
    $dateshift $_POST["dateshift"]; 
        
    $shift $_POST["shift"]; 
         
        
    $totalarr count($opname) - 1
        for(
    $ctr=0$ctr $totalarr$ctr++) 
            { 
            
    $inqty[$ctr] = (float) $inqty[$ctr]; 
            
    $varqty[$ctr] = (float) $varqty[$ctr]; 
            
    $outqty[$ctr] = (float) $outqty[$ctr]; 
            
    $query "INSERT INTO traceability (operation_name, time_in, time_out, input_qty, input_unit, output_qty, output_unit, id_no, mc_no, variance_qty, variance_sublot, date, shift, transact_id) VALUES ('" $opname[$ctr] . "', '" $timein[$ctr] . "', '" $timeout[$ctr] . "', '" $inqty[$ctr] . "' , '" $iun[$ctr] . "' ,'" $outqty[$ctr] . "', '" $oun[$ctr] . "' , '" $idno[$ctr] . "', '" $mcno[$ctr] . "', '" $varqty[$ctr] . "', '" $varsublot[$ctr] . "', '" $dateshift[$ctr] . "', '" $shift[$ctr] . "', '" $transact_id "')"
            
    $result mysql_query($query); 
             
            }    
        } 
    $rexist 0
    ?> 
    <html> 
    <head> 
        <script language="javascript"> 
        function handleEnter(e, nextfield) 
            { 
            var characterCode = (e && e.which)? e.which: e.keyCode; 
            if(characterCode == 13) 
                { 
                document.getElementById(nextfield).focus(); 
                return false; 
                }  
            else 
                { 
                return true; 
                } 
            } 
        </script> 
    </head> 
    <body onLoad="document.type.no.focus();"> 
    <!--<p><a href="definition.php">Types</a><a href="query.php">Query</a></p>--> 
    <?php 
    include("menu.php"); 
    ?> 
    <form action="main.php" method="post" name="type"> 
    <?php 
        $rexist 
    1
        echo 
    "<p>No:<input type='text' name='_no' onkeypress='return handleEnter(event,\"date\");' /><br />"
        echo 
    "Date:;<input type='text' name='date' onkeypress='return handleEnter(event,\"ac2l\");' /></p>"
         
        echo 
    "<table>"
        echo 
    "<tr><th class='myclass'>TRACEABILITY</th><th class='myclass'>LOT #</th></tr>"
        echo 
    "<tr><td>AC2L</td><td><input type='text' name='ac2l' id='ac2l' onkeypress='return handleEnter(event,\"b3\");' /></td></tr>"
        echo 
    "<tr><td>B3</td><td><input type='text' name='b3' id='b3' onkeypress='return handleEnter(event,\"type\");' /></td></tr>"
        echo 
    "<tr><td>Type</td><td><input type='text' name='type' id='type' onkeypress='return handleEnter(event,\"roll\");' /></td></tr>"
        echo 
    "<tr><td>Roll</td><td><input type='text' name='roll' id='roll' onkeypress='return handleEnter(event,\"timein0\");' /></td></tr>"
        echo 
    "</table>"
        echo 
    "<p>&nbsp;</p>"
         
        
    $query "SELECT * FROM trace_operations ORDER BY operation_name"
        
    $last_operation_name ""
        
    $result mysql_query($query); 
        if(
    $result
            { 
            
    $rexist 1
            echo 
    "<p><center><b>TRACEABILITY</center></b></p>"
            echo 
    "<table>"
            echo 
    "<tr><th class='myclass'>OPERATIONS</th><th class='myclass'>Time IN</th><th class='myclass'>Time OUT</th><th class='myclass'>INPUT <br/> QTY</th><th class='myclass'>UNIT</th><th class='myclass'>OUTPUT QTY</th><th class='myclass'>UNIT</th><th class='myclass'>NAME & ID #</th><th class='myclass'>MC #</th><th class='myclass'>VARIANCE Qty</th><th class='myclass'>VARIANCE Sub Lot</th><th class='myclass'>DATE</th><th class='myclass'>SHIFT</th></tr>"
            
    $totalrows mysql_num_rows($result); 
            
    $trows $totalrows 1
            for(
    $ctr 0$ctr $trows$ctr++) 
                { 
                
    $row mysql_fetch_array($result); 
                
    $tctr $ctr 1
                echo 
    "\n\t<tr>"
                echo 
    "\n\t\t<td>"
                if (
    $last_operation_name != $row["operation_name"]) echo $row["operation_name"]; 
                
    $last_operation_name $row["operation_name"]; 
                echo 
    "<input type='hidden' name='opname[]' value='" $row["operation_name"] . "' /></td>";    
                echo 
    "\n\t\t<td><input type='text' name='timein[]' id='timein" $ctr "' onkeypress='return handleEnter(event,\"timeout" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td><input type='text' name='timeout[]' id='timeout" $ctr "' onkeypress='return handleEnter(event,\"inqty" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td><input type='text' name='inqty[]' id='inqty" $ctr "' onkeypress='return handleEnter(event,\"outqty" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td>" $row["input_unit"]; 
                echo 
    "<input type='hidden' name='iun[]' value='" $row["input_unit"] . "' /></td>"
                echo 
    "\n\t\t<td><input type='text' name='outqty[]' id='outqty" $ctr "' onkeypress='return handleEnter(event,\"idno" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td>" $row["output_unit"]; 
                echo 
    "<input type='hidden' name='oun[]' value='" $row["output_unit"] . "'></td>"
                echo 
    "\n\t\t<td><input type='text' name='idno[]' id='idno" $ctr "' onkeypress='return handleEnter(event,\"mcno" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td><input type='text' name='mcno[]' id='mcno" $ctr "' onkeypress='return handleEnter(event,\"varqty" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td><input type='text' name='varsublot[]' id='varsublot" $ctr "' onkeypress='return handleEnter(event,\"dateshift" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td><input type='text' name='dateshift[]' id='dateshift" $ctr "' onkeypress='return handleEnter(event,\"shift" $ctr "\");' /></td>"
               echo 
    "\n\t\t<td><input type='text' name='shift[]' id='shift" $ctr "' onkeypress='return handleEnter(event,\"timein" $tctr "\");' /></td>"
                echo 
    "\n\t</tr>"
                } 
            if(
    $totalrows 1); 
                { 
                
    $row mysql_fetch_array($result); 
                echo 
    "\n\t<tr>"
                echo 
    "\n\t\t<td>"
                if (
    $last_operation_name != $row["operation_name"]) echo $row["operation_name"]; 
                
    $last_operation_name $row["operation_name"]; 
                echo 
    "<input type='hidden'  name='opname[]' value='" $row["operation_name"] . "' /></td>";    
                echo 
    "<input type='hidden' name='opname[]' value='" $row["operation_name"] . "' /></td>"
                echo 
    "\n\t\t<td><input  type='text' name='timein[]' id='timein" $ctr "' onkeypress='return handleEnter(event,\"timeout" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td><input  type='text' name='timeout[]' id='timeout" $ctr "' onkeypress='return handleEnter(event,\"inqty" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td><input  type='text' name='inqty[]' id='inqty" $ctr "' onkeypress='return handleEnter(event,\"outqty" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td>" $row["input_unit"]; 
                echo 
    "<input type='hidden' name='iun[]' value='" $row["input_unit"] . "' /></td>"
                echo 
    "\n\t\t<td><input  type='text' name='outqty[]' id='outqty" $ctr "' onkeypress='return handleEnter(event,\"idno" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td>" $row["output_unit"]; 
                echo 
    "<input type='hidden' name='oun[]' value='" $row["output_unit"] . "'></td>"
                echo 
    "\n\t\t<td><input  type='text' name='idno[]' id='idno" $ctr "' onkeypress='return handleEnter(event,\"mcno" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td><input type='text' name='mcno[]' id='mcno" $ctr "' onkeypress='return handleEnter(event,\"varqty" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td><input type='text' name='varqty[]' id='varqty" $ctr "' onkeypress='return handleEnter(event,\"varsublot" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td><input type='text' name='varsublot[]' id='varsublot" $ctr "' onkeypress='return handleEnter(event,\"dateshift" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td><input type='text' name='dateshift[]' id='dateshift" $ctr "' onkeypress='return handleEnter(event,\"shift" $ctr "\");' /></td>"
                echo 
    "\n\t\t<td><input type='text' name='shift[]' id='shift" $ctr "' onkeypress='return handleEnter(event,\"saveform\");' /></td>"
                echo 
    "\n\t</tr>"
                } 
            echo 
    "</table>"
            } 
        echo 
    "<p><input type='submit' value='  Save  ' id='saveform' /></p>"
        echo 
    "<input type='hidden' name='typeno' value='" $_POST["typeno"] . "' />"
    ?> 
    </form> 
    </body> 
    </html> 
    Honestly, I don't know where i can put the code you suggeted. I really need to fix this problem, i don't know why, I'm sorry I'm not good in coding and analyzing.

    I only want is the input and output should be subtract and the result would appear in varqty text field. when they press enter key.
    Thank you
     
  15. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Now my code does exactly the same. Would you mind running my code.
     
  16. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines
    Where i can put that code?
    <INPUT TYPE="text" NAME="qty1" Value="">
    <INPUT TYPE="text" NAME="qty2" value="">
    <INPUT TYPE="text" NAME="res" value="">
    <INPUT TYPE="submit" onClick="res.value=qty1.value-qty2.value">
     
  17. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines
    this code is for subtraction of input and output
    Code:
    <html>
    <head>
    <script type= "text/javascript">
    function startCalc(){
      interval = setInterval("calc()",1);
     }
    function calc(){
     var qty = new Array(2);
     qty[0] = parseFloat(document.myform.inqty.value);
      qty[1] = parseFloat(document.myform.outqty.value);
      
    myqtyval = qty[0]-qty[1];
    document.myform.myqty.value = myqtyval; 
    }
    function stopCalc(){
      clearInterval(interval);
    }
    </script>
    </head>
    <body>
    <form name='myform' action='test.php' method='post'>
    Input<input type='text' name='inqty'  onFocus='startCalc();' onBlur='stopCalc();' />
    Output<input type='text' name='outqty'  onFocus='startCalc();' onBlur='stopCalc();' /><br/>
    myqty<input type='text' name='myqty' value=''  />
    <input type='submit' name='submit' value='save' />
    
    </form>
    </body>
    </html>
    
    My problem is how can I insert this code in my real codes where i need to have to subtract automatic the input and output of operation name 01 Spreading and 03 Setting. I'm sorry because I'm not good in mixing codes.
    Code:
    <?php
    include("config.php");
    $rexist = 0;
    if($_POST["clt_no"])
        {
        $clt_date = $_POST["clt_date"];
        $query = "INSERT INTO clt_transact (clt_no, ac2l, b3, cloth_type, roll_no, transact_date, clt_date, pack_setting) VALUES ('" . $_POST["clt_no"] . "', '" . $_POST["ac2l"] . "', '" . $_POST["b3"] . "', '" . $_POST["cloth_type"] . "', '" . $_POST["roll_no"] . "', now(), '" . $clt_date . "', '" . $_POST["pack"] . "')";
        $result = mysql_query($query);
        $clt_transact_id = mysql_insert_id();
        
        $opname = $_POST["opname"];
        $timein = $_POST["timein"];
        $timeout = $_POST["timeout"];
        $inqty = $_POST["inqty"];
        $iun = $_POST["iun"];
        $outqty = $_POST["outqty"];
        $oun = $_POST["oun"];
        $idno = $_POST["idno"];
        $mcno = $_POST["mcno"];
        $varqty = $_POST["varqty"];
        $varsublot = $_POST["varsublot"];
        $dateshift = $_POST["dateshift"];
        $shift = $_POST["shift"];
        
        $totalarr = count($opname) - 1;
        for($ctr=0; $ctr < $totalarr; $ctr++)
            {
            $inqty[$ctr] = (float) $inqty[$ctr];
            $varqty[$ctr] = (float) $varqty[$ctr];
            $outqty[$ctr] = (float) $outqty[$ctr];
            $query = "INSERT INTO clt_traceability (operation_name, time_in, time_out, input_qty, input_unit, output_qty, output_unit, id_no, mc_no, variance_qty, variance_sublot, date, shift, clt_transact_id) VALUES ('" . $opname[$ctr] . "', '" . $timein[$ctr] . "', '" . $timeout[$ctr] . "', '" . $inqty[$ctr] . "' , '" . $iun[$ctr] . "' ,'" . $outqty[$ctr] . "', '" . $oun[$ctr] . "' , '" . $idno[$ctr] . "', '" . $mcno[$ctr] . "', '" . $varqty[$ctr] . "', '" . $varsublot[$ctr] . "', '" . $dateshift[$ctr] . "', '" . $shift[$ctr] . "', '" . $clt_transact_id . "')";
            $result = mysql_query($query);
            
            }   
        }
    $rexist = 0;
    ?>
    <html>
    <head>
        <script language="javascript">
        function handleEnter(e, nextfield)
            {
            var characterCode = (e && e.which)? e.which: e.keyCode;
            if(characterCode == 13)
                {
                document.getElementById(nextfield).focus();
                return false;
                } 
            else
                {
                return true;
                }
            }
        </script>
    </head>
    <body onLoad="document.clttype.clt_no.focus();">
    <!--<p><a href="clt_definition.php">Clt Types</a>&nbsp;&nbsp;&nbsp;<a href="clt_query.php">Query</a></p>-->
    <?php
    include("menu.php");
    ?>
    <form action="clt_main.php" method="post" name="clttype">
    <?php
        $rexist = 1;
        
        echo "Clt No:<input type='text' name='clt_no' onkeypress='return handleEnter(event,\"clt_date\");' />";
        echo "<input type='radio' name='pack' id='mother' value='Mother Lot'  /> Mother Lot<br />";   
        echo "CLT Date:<input type='text' name='clt_date' onkeypress='return handleEnter(event,\"ac2l\");' />";
        echo "<input type='radio' name='pack' id='child' value='Child Lot' /> Child Lot";
          
        echo "<table>";
        echo "<tr><th class='myclass'>PARTS</th><th class='myclass'>LOT/BATCH #</th></tr>";
        echo "<tr><td>AC2L</td><td><input type='text' name='ac2l' id='ac2l' onkeypress='return handleEnter(event,\"b3\");' /></td></tr>";
        echo "<tr><td>B3</td><td><input type='text' name='b3' id='b3' onkeypress='return handleEnter(event,\"cloth_type\");' /></td></tr>";
        echo "<tr><td>Cloth Type</td><td><input type='text' name='cloth_type' id='cloth_type' onkeypress='return handleEnter(event,\"roll_no\");' /></td></tr>";
        echo "<tr><td>Roll No</td><td><input type='text' name='roll_no' id='roll_no' onkeypress='return handleEnter(event,\"timein0\");' /></td></tr>";
        echo "</table>";
        echo "<p>&nbsp;</p>";
        
        $query = "SELECT * FROM clt_trace_operations ORDER BY operation_name";
        $last_operation_name = "";
        $result = mysql_query($query);
        if($result)
            {
            $rexist = 1;
            echo "<p><center><b>OPERATOR AND MACHINE TRACEABILITY</center></b></p>";
            echo "<table>";
            echo "<tr><th class='myclass'>OPERATIONS</th><th class='myclass'>Time IN</th><th class='myclass'>Time OUT</th><th class='myclass'>INPUT <br/> QTY</th><th class='myclass'>UNIT</th><th class='myclass'>OUTPUT QTY</th><th class='myclass'>UNIT</th><th class='myclass'>ID #</th><th class='myclass'>MC #</th><th class='myclass'>VARIANCE Qty</th><th class='myclass'>VARIANCE Sub Lot</th><th class='myclass'>DATE</th><th class='myclass'>SHIFT</th></tr>";
            $totalrows = mysql_num_rows($result);
            $trows = $totalrows - 1;
            for($ctr = 0; $ctr < $trows; $ctr++)
                {
                $row = mysql_fetch_array($result);
                $tctr = $ctr + 1;
                echo "\n\t<tr>";
                echo "\n\t\t<td>";
                if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
                $last_operation_name = $row["operation_name"];
                echo "<input type='hidden' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";   
                echo "\n\t<td><input  type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,\"timeout" . $ctr . "\");' /></td>";
                echo "\n\t<td><input  type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,\"inqty" . $ctr . "\");' /></td>";
                echo "\n\t<td><input  type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";
                echo "\n\t<td>" . $row["input_unit"];
                echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
                echo "\n\t<td><input  type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
                echo "\n\t<td>" . $row["output_unit"];
                echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
                echo "\n\t<td><input  type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,\"mcno" . $ctr . "\");' /></td>";
                echo "\n\t<td><input  type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,\"varqty" . $ctr . "\");' /></td>";
                echo "\n\t<td><input  type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";
                echo "\n\t<td><input  type='text' name='varsublot[]' id='varsublot" . $ctr . "' onkeypress='return handleEnter(event,\"dateshift" . $ctr . "\");' /></td>";
                echo "\n\t<td><input ' type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,\"shift" . $ctr . "\");' /></td>";
               echo "\n\t<td><input  type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"timein" . $tctr . "\");' /></td>";
                echo "\n\t</tr>";
                }
            if($totalrows > 1);
                {
                $row = mysql_fetch_array($result);
                echo "\n\t<tr>";
                echo "\n\t<td >";
                if ($last_operation_name != $row["operation_name"]) echo $row["operation_name"];
                $last_operation_name = $row["operation_name"];
                echo "<input type='hidden'  name='opname[]' value='" . $row["operation_name"] . "' /></td>";   
                echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>";
                echo "\n\t<td><input  type='text' name='timein[]' id='timein" . $ctr . "' onkeypress='return handleEnter(event,\"timeout" . $ctr . "\");' /></td>";
                echo "\n\t<td><input  type='text' name='timeout[]' id='timeout" . $ctr . "' onkeypress='return handleEnter(event,\"inqty" . $ctr . "\");' /></td>";
                echo "\n\t<td><input  type='text' name='inqty[]' id='inqty" . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";
                echo "\n\t<td>" . $row["input_unit"];
                echo "<input type='hidden' name='iun[]' value='" . $row["input_unit"] . "' /></td>";
                echo "\n\t<td><input  type='text' name='outqty[]' id='outqty" . $ctr . "' onkeypress='return handleEnter(event,\"idno" . $ctr . "\");' /></td>";
                echo "\n\t<td>" . $row["output_unit"];
                echo "<input type='hidden' name='oun[]' value='" . $row["output_unit"] . "'></td>";
                echo "\n\t<td><input  type='text' name='idno[]' id='idno" . $ctr . "' onkeypress='return handleEnter(event,\"mcno" . $ctr . "\");' /></td>";
                echo "\n\t<td><input  type='text' name='mcno[]' id='mcno" . $ctr . "' onkeypress='return handleEnter(event,\"varqty" . $ctr . "\");' /></td>";
                echo "\n\t<td><input  type='text' name='varqty[]' id='varqty" . $ctr . "' onkeypress='return handleEnter(event,\"varsublot" . $ctr . "\");' /></td>";
                echo "\n\t<td><input  type='text' name='varsublot[]' id='varsublot" . $ctr . "' onkeypress='return handleEnter(event,\"dateshift" . $ctr . "\");' /></td>";
                echo "\n\t<td><input  type='text' name='dateshift[]' id='dateshift" . $ctr . "' onkeypress='return handleEnter(event,\"shift" . $ctr . "\");' /></td>";
                echo "\n\t<td><input  type='text' name='shift[]' id='shift" . $ctr . "' onkeypress='return handleEnter(event,\"saveform\");' /></td>";
                echo "\n\t</tr>";
                }
            echo "</table>";
            }       
        echo "<p><input type='submit' value='  Save  ' id='saveform' /></p>";
        echo "<input type='hidden' name='clt_typeno' value='" . $_POST["clt_typeno"] . "' />";
    ?>
    </form>
    </body>
    </html>
    
     
  18. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Why you want to mix them is not at all what I can understand. It can be a separate HTML bunch as well in the file.
     
  19. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines
    Actually, not all operation name will subtract the input and output only in oper1,oper3,oper4,and oper5.

    my idea is select those operation then do the condition to subtract the input and output but i don't where in my codes I can do that.

    I attach my wholecode
     

    Attached Files:

  20. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines
    I have the select statement code where only those operation name could subtract the input and output
    Code:
    SELECT t.operation_name FROM clt_traceability t, clt_transact c WHERE t.operation_name in ('operation_name1', 'operation_name3', 'operation_name4', 'operation_name5') AND t.clt_transact_id = c.clt_transact_id
    
    my problem is where i can put this code in my php file and how thus the input and output subtract nad automatic the varqty was appear as the result of subtration of input and output.

    Thank you...
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice