6 Replies - 1216 Views - Last Post: 14 December 2010 - 11:01 PM Rate Topic: -----

#1 Rhoda Rose  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 93
  • Joined: 21-June 10

Sum of table rows data and the result will appear in a textfield

Posted 13 December 2010 - 01:43 AM

Good day!

I have a problem in adding codes in my php codes, but i have the concept of codes that i want to add in my php codes, but I don't know if it is right. Kindly check my codes thank you.

I attached my whole codes for better understanding

and here is the codes I want to add:
<?php
  if($_POST["clt_no"])
    {
    $query = "SELECT * FROM clt_transact WHERE  clt_no = '" . $_POST . "'";
    $result_no = mysql_query($query);
        if($result_no)
            {
            if(mysql_num_rows($result_no) > 0 )
            $operation2_input = 0;
            
            $query = "SELECT SUM(t.input_qty) AS operation_input FROM clt_traceability t, clt_transact p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name 'Operation2' 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");
                }
              $operation2_total = $operation2_input;
            }
    }
?>



I want to happen is all the input qty that the user insert in input qty textfield will sum and the result will appear in operation2_total in input_qty textfield.

I don't know how thus the result should be appear automatically in the input qty of operation2_total and if my code is correct.

Thank you

Attached File(s)


This post has been edited by Rhoda Rose: 13 December 2010 - 01:44 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Sum of table rows data and the result will appear in a textfield

#2 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: Sum of table rows data and the result will appear in a textfield

Posted 13 December 2010 - 06:11 AM

On line 5 I see that you are using the whole $_POST array in your query rather than $_POST['element']. I'm guessing that alone would throw off your application. Also you should look into data scrubbing and SQL injection prevention techniques as using a posted value directly in querying without prepared statements is a major security vulnerability. Hope this helps :)
Was This Post Helpful? 0
  • +
  • -

#3 Rhoda Rose  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 93
  • Joined: 21-June 10

Re: Sum of table rows data and the result will appear in a textfield

Posted 13 December 2010 - 05:06 PM

View PostJstall, on 13 December 2010 - 05:11 AM, said:

On line 5 I see that you are using the whole $_POST array in your query rather than $_POST['element']. I'm guessing that alone would throw off your application. Also you should look into data scrubbing and SQL injection prevention techniques as using a posted value directly in querying without prepared statements is a major security vulnerability. Hope this helps :)

I'm sorry, it should be like this:

$query = "SELECT * FROM clt_transact WHERE  clt_no = '" . $_POST["clt_no"] . "'";



I'm not good in coding but i tried to be good.
Was This Post Helpful? 0
  • +
  • -

#4 Rhoda Rose  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 93
  • Joined: 21-June 10

Re: Sum of table rows data and the result will appear in a textfield

Posted 14 December 2010 - 05:37 PM

This is my new code for the sum of input qty in operation2
<?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) > 0 )
            $clicking_input = 0;
            $clicking_total = 0;
            
            $query = "SELECT t.input_qty AS clicking_input FROM clt_traceability t, p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name '02 Clicking' AND p.clt_no='" . $_POST["clt_no"] . "'";
            $resultyield = mysql_query($query);
            if($resultyield)
                {
                    if(mysql_num_rows($resultyield) > 0)$clicking_input =mysql_result($resultyield,0,"clicking_input");
                }
          /*  $query = "SELECT SUM(t.input_qty) AS clicking_input FROM clt_traceability t, clt_transact p WHERE t.clt_transact_id = p.clt_transact_id AND t.operation_name '02 Clicking' AND p.clt_no='" . $_POST["clt_no"] . "'";
            $resultyield = mysql_query($query);
            if($resultyield)
                {
                    if(mysql_num_rows($resultyield) > 0)$clicking_input =mysql_result($resultyield,0,"clicking_input");
                }*/
            $query = "SELECT operation_name FROM clt_traceability t, clt_transact c WHERE t.operation_name = '02 Clicking Total' AND t.clt_transact_id = c.clt_transact_id";
            $result = mysql_query($query);
            if($result > 0)
            {           
            $clicking_total = $clicking_input;
            //pano automatic mag eecho o mag aappear ung sum ng inqty sa inqty ng clicking total
            }
            }
    }
$rexist = 0;
?>

<html>
<head>
    <style type="text/css">
    .myclass {
     font-size: 10pt; font-family:Arial, Helvetica, sans-serif;
    }
    </style>
    
    <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.clttest.clt_no.focus();">
<form action='test5.php' method="post" name="clttest">
<?php
    $rexist = 1;
    
    $query = "SELECT * FROM clt_trace_operations ORDER BY operation_name";
    $last_operation_name = "";
    $result = mysql_query($query);
    if($result)
        {
        $rexist = 1;
        
        echo "<table>";
        echo "<tr><th>Operation</th><th>Inqty</th><th>Outqty</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\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,\"inqty" . $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' width='400' name='opname[]' value='" . $row["operation_name"] . "' /></td>";   
            echo "<input type='hidden' name='opname[]' value='" . $row["operation_name"] . "' /></td>"; 
            echo "\n\t\t<td><input size='6' type='text' name='inqty[]' value='$clicking_total' 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,\"saveform" . $ctr . "\");' /></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"] . "' />";
?>



for adding the sum of input qty of operation 2 and the output should be appear in operation2_total input qty text field. In my code I don't have any error but it did not work.
Was This Post Helpful? 0
  • +
  • -

#5 Rhoda Rose  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 93
  • Joined: 21-June 10

Re: Sum of table rows data and the result will appear in a textfield

Posted 14 December 2010 - 10:33 PM

I have 5 operation name: operation1,operation2,operation2_total,operation3,operation4,operation5. As you notice I have a operation2_total

How can I add the input qty of operation2 and the result will be appear in input_qty of operation2_total.

Thank you

Attached File(s)


This post has been edited by Rhoda Rose: 14 December 2010 - 10:37 PM

Was This Post Helpful? 0
  • +
  • -

#6 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 931
  • View blog
  • Posts: 3,216
  • Joined: 19-January 10

Re: Sum of table rows data and the result will appear in a textfield

Posted 14 December 2010 - 10:56 PM

Use the code tags. I'm not even going to bother opening that up.
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6635
  • View blog
  • Posts: 30,898
  • Joined: 10-May 07

Re: Sum of table rows data and the result will appear in a textfield

Posted 14 December 2010 - 11:01 PM

It's an even trade, because the op won't bother using the code tags.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1