1. This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
    For information on cookies and how you can disable them visit our Cookie Usage page.
    Dismiss Notice

PHP Sum of input will appear in a total input textfield

Discussion in 'Web Development' started by newphpcoder, Dec 16, 2010.

  1. newphpcoder

    newphpcoder New Member

    I have a problem in the sum of input qty of operation2 and the result will appear in input qty of operation2_total

    I have this code for the condition of sum of input qty of operation2

    PHP:
    <?php
     
    include 'config.php';
    $rexist 0;
    if(
    $_POST["clt_no"])
    {
       
    $opname $_POST["opname"];
       
    $inqty $_POST["inqty"];
       
    $outqty $_POST["outqty"];
       
       
    $totalarr count($opname) - 1;
        for(
    $ctr=0$ctr $totalarr$ctr++)
            {
            
    $inqty[$ctr] = (float) $inqty[$ctr];
            
    $outqtyqty[$ctr] = (float) $outqty[$ctr];
            
             
    $query "INSERT INTO clt_traceability (operation_name, input_qty, clt_transact_id) VALUES ('" $opname[$ctr] . "',  '" $inqty[$ctr] . "', '" $outqty[$ctr] . "', '" $clt_transact_id "')";
            
    $result mysql_query($query);
            }   
            
        
    $query "SELECT * FROM clt_transact WHERE  clt_no = '" $_POST["clt_no"] . "'";
        
    $result_no mysql_query($query);
            if(
    $result_no)
                {
                if(
    mysql_num_rows($result_no) > )
                {
                
    $operation2_input 0;
                
    $operation2total_total 0;
                
                
    $query "SELECT t.input_qty AS operation2_input FROM clt_traceability t, p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name 'Operation 2' AND p.clt_no='" $_POST["clt_no"] . "'";
                
    $resultyield mysql_query($query);
                if(
    $resultyield)
                    {
                        if(
    mysql_num_rows($resultyield) > 0)$operation2_input =mysql_result($resultyield,0,"operation2_input");
                    }
            
                
    $query "SELECT operation_name FROM clt_traceability t, clt_transact c WHERE t.operation_name = 'Operation 2 Total' AND t.clt_transact_id = c.clt_transact_id";
                
    $result mysql_query($query);
                if(
    $result 0)
                {           
                 
    $operation2total_total $operation2_input;
               
                }
                }
        }
    }
    $rexist 0;
    ?>
     
    echo "\n\t\t<td><input size='6' type='text' name='inqty[]' [COLOR="Blue"]value='$operation2total_total'[/COLOR] id='inqty"  . $ctr . "' onkeypress='return handleEnter(event,\"outqty" . $ctr . "\");' /></td>";


    this code was not work but theres no error.

    I attach my full code where i want to add this code
     

    Attached Files:

  2. enigma1

    enigma1 New Member

    Do you have a table named p? if not the query should give an error

    Code:
    [SIZE=3][FONT=Times New Roman][COLOR=#000000][COLOR=#DD0000]FROM clt_traceability t, p WHERE
    [/COLOR][/COLOR][/FONT][/SIZE]
    If you don't see an error it means the code is not executed so the previous query may be the culprit.

    Code:
    [SIZE=3][FONT=Times New Roman][COLOR=#000000][COLOR=#007700][/COLOR][COLOR=#0000BB]$query [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#DD0000]"SELECT * FROM clt_transact WHERE  clt_no = '" [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000BB]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#DD0000]"clt_no"[/COLOR][COLOR=#007700]] . [/COLOR][COLOR=#DD0000]"'"[/COLOR][COLOR=#007700];
    [/COLOR][/COLOR][/FONT][/SIZE]
    Use print_r or dump and see which part of the code is executed. Also instead of the if command to test the queries use directly the mysql_num_rows.

    instead of:
    if($result_no)
    {
    if(
    mysql_num_rows($result_no) > 0 )
    {
    use just:
    if(mysql_num_rows($result_no) ) ......