Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Problem in Subtraction
Old 12-08-2010, 09:20 PM Problem in Subtraction
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
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 Code:
<?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..
newphpcoder is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-11-2010, 11:41 PM Re: Problem in Subtraction
Extreme Talker

Posts: 246
Trades: 3
Are you trying to subtract values coming from the SQL data, or from values entered on the webpage's form?

If the data comes from SQL:
PHP Code:
<?php
//make sure the field names, table name and conditions are accurate
$sql "select input_qty, output_qty from example_tablename where example_field = 1";
$sqlresult mysql_query($sql) or die("Error executing SQL query");
$row mysql_fetch_array($sqlresult);
$inqty $row['input_qty'];
$outqty $row['output_qty'];
$qty $inqty $outqty;
?>
<html>
<body>
Input_Qty: <?php echo $inqty?>
Output_Qty: <?php echo $outqty?>
Qty (In - Out): <?php echo $qty?>
</body>
</html>

If the data comes from the form:
PHP Code:
<?php
$inqty 
$_POST['input_qty'];
$outqty $_POST['output_qty'];
$qty $inqty $outqty;
?>
<html>
<body>
<form method="post" action="thispage.php"> <!-- thispage.php is whatever this page's filename is -->
Input_Qty: <input type="text" name="input_qty" value="<?php echo $inqty?>" />
Output_Qty:  <input type="text" name="output_qty" value="<?php echo $outqty?>" />
Qty (In - Out):  <input type="text" name="qty" value="<?php echo $qty?>" />
</form>
</body>
</html>

?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
CouponGuy is offline
Reply With Quote
View Public Profile
 
Old 12-12-2010, 07:13 PM Re: Problem in Subtraction
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
Quote:
Originally Posted by CouponGuy View Post
Are you trying to subtract values coming from the SQL data, or from values entered on the webpage's form?

If the data comes from SQL:
PHP Code:
<?php
//make sure the field names, table name and conditions are accurate
$sql "select input_qty, output_qty from example_tablename where example_field = 1";
$sqlresult mysql_query($sql) or die("Error executing SQL query");
$row mysql_fetch_array($sqlresult);
$inqty $row['input_qty'];
$outqty $row['output_qty'];
$qty $inqty $outqty;
?>
<html>
<body>
Input_Qty: <?php echo $inqty?>
Output_Qty: <?php echo $outqty?>
Qty (In - Out): <?php echo $qty?>
</body>
</html>

If the data comes from the form:
PHP Code:
<?php
$inqty 
$_POST['input_qty'];
$outqty $_POST['output_qty'];
$qty $inqty $outqty;
?>
<html>
<body>
<form method="post" action="thispage.php"> <!-- thispage.php is whatever this page's filename is -->
Input_Qty: <input type="text" name="input_qty" value="<?php echo $inqty?>" />
Output_Qty:  <input type="text" name="output_qty" value="<?php echo $outqty?>" />
Qty (In - Out):  <input type="text" name="qty" value="<?php echo $qty?>" />
</form>
</body>
</html>
 
?>
I try the 2nd code you suggested:
PHP Code:
<?php
 $inqty 
$_POST["inqty"];
$outqty $_POST["outqty"];
$varqty $_POST["varqty"];
$varqty $inqty $outqty
 
echo 
"\n\t\t<td><input size='6' type='text' name='inqty[]' value='<?php echo $inqty; ?>' id='inqty"  $ctr "' onkeypress='return handleEnter(event,\"outqty" $ctr "\");' /></td>";
 echo 
"\n\t\t<td><input size='6' type='text' name='outqty[]' value='<?php echo $outqty; ?>'  id='outqty" $ctr "' onkeypress='return handleEnter(event,\"idno" $ctr "\");' /></td>";
echo 
"\n\t\t<td><input size='6' type='text' name='varqty[]' value='<?php echo $varqty; ?>' id='varqty" $ctr "' onkeypress='return handleEnter(event,\"varsublot" $ctr "\");' /></td>";\
?>
And I got this error:
and at the last row textfield, the php echo was appear
Fatal error: Unsupported operand types in D:\xampp\htdocs\INTRANET\clt_main.php on line 26

Last edited by newphpcoder; 12-12-2010 at 07:18 PM..
newphpcoder is offline
Reply With Quote
View Public Profile
 
Old 12-12-2010, 08:58 PM Re: Problem in Subtraction
Extreme Talker

Posts: 246
Trades: 3
If you are echoing the html in your code (instead of using the code I posted) then you want to do something like this instead:

Note:I'm only posting one line of code, and not the entire section.

PHP Code:
echo "\n\t\t<td><input size='6' type='text' name='inqty[]' value='" $inqty "' id='inqty"  $ctr "' onkeypress='return handleEnter(event,\"outqty" $ctr "\");' /></td>"
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
CouponGuy is offline
Reply With Quote
View Public Profile
 
Old 12-12-2010, 09:08 PM Re: Problem in Subtraction
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
Quote:
Originally Posted by CouponGuy View Post
If you are echoing the html in your code (instead of using the code I posted) then you want to do something like this instead:

Note:I'm only posting one line of code, and not the entire section.

PHP Code:
echo "\n\t\t<td><input size='6' type='text' name='inqty[]' value='" $inqty "' id='inqty"  $ctr "' onkeypress='return handleEnter(event,\"outqty" $ctr "\");' /></td>"

I got an error

inqty is null or not an object
newphpcoder is offline
Reply With Quote
View Public Profile
 
Old 12-12-2010, 10:02 PM Re: Problem in Subtraction
Extreme Talker

Posts: 246
Trades: 3
Want to post your whole page? That way I can stop guessing...
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
CouponGuy is offline
Reply With Quote
View Public Profile
 
Old 12-12-2010, 10:12 PM Re: Problem in Subtraction
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
Quote:
Originally Posted by CouponGuy View Post
Want to post your whole page? That way I can stop guessing... :)

I attach my whole code and you can see the new code that I added which is for calculation of varqty and it did not work..i really don't know how can i do what my boss want it to happen. I understand but I can' code it.:confused:

Thank you
Attached Files
File Type: txt main.txt (12.9 KB, 3 views)

Last edited by newphpcoder; 12-12-2010 at 10:26 PM..
newphpcoder is offline
Reply With Quote
View Public Profile
 
Old 12-12-2010, 10:34 PM Re: Problem in Subtraction
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
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...
newphpcoder is offline
Reply With Quote
View Public Profile
 
Old 12-12-2010, 10:55 PM Re: Problem in Subtraction
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
this codes:
HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<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>
has the concept of what i want that after i insert number in output the result was automatically appear in qty but the problem in this code it did not use on key enter and I don't know how can i put that code n my php file where I attach.
I'm sorry, i do understand the concept but I don't know how can I code it and where i can put the codes.

Thank you..
newphpcoder is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 12:41 AM Re: Problem in Subtraction
Extreme Talker

Posts: 246
Trades: 3
You're almost there. To get the form submit button to subtract one value from another, try this. Instead of the onfocus running the javascript calculation, the form's action (upon submitting) will run the javascript calculation.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<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='javascript:startCalc();' method='post'>
Input<input type='text' name='inqty' />
Output<input type='text' name='outqty'  /><br/>
myqty<input type='text' name='myqty' value=''  />
<input type='submit' name='submit' value='save' />
 
 
</form>
</body>
</html>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
CouponGuy is offline
Reply With Quote
View Public Profile
 
Old 12-13-2010, 12:57 AM Re: Problem in Subtraction
Skilled Talker

Posts: 97
Name: rhoda
Trades: 0
Quote:
Originally Posted by CouponGuy View Post
You're almost there. To get the form submit button to subtract one value from another, try this. Instead of the onfocus running the javascript calculation, the form's action (upon submitting) will run the javascript calculation.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<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='javascript:startCalc();' method='post'>
Input<input type='text' name='inqty' />
Output<input type='text' name='outqty'  /><br/>
myqty<input type='text' name='myqty' value=''  />
<input type='submit' name='submit' value='save' />
 
 
</form>
</body>
</html>
Kindly check the file that I attached.

I put that code in my php file. And it did not work.. I don't know why. After i insert numbers in input text area and i enter and I insert number in output the result did not appear in varqty.:confused:
Attached Files
File Type: txt cmain2.txt (11.7 KB, 0 views)
newphpcoder is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Problem in Subtraction
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31957 seconds with 13 queries