RE: [PHP] Looping Addition
- Original Message - From: Chris Wesley [EMAIL PROTECTED] To: PHP List [EMAIL PROTECTED] On Wed, 4 Dec 2002, Stephen wrote: This is only a snippet, there is more to it but for simplicities sake... Then I calculate it. My question is, how would I loop the adding? I hope you understand this now... Ah!, I think I understand better now. You want to add num1, num2, num3, ... numN, which are inputs from the second form in your sequence. Gotcha. If you name /all/ the form elements as nums[] instead of individually as num${current}, the numbers put into the form will all be accessible in one array to the PHP script that does the adding. Then you can just loop over the array of numbers. In your second form, change this: input name=num?php echo $current; ? type=text id=vars value=0 size=25 To this: input name=nums[] type=text id=vars value=0 size=25 Then in the script that adds the numbers: $total = 0; foreach( $_POST['nums'] as $number ){ $total += $number; } Or even $total = array_sum($_POST['nums']) Cheers! Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
One more question... If I then wanted to do this for the other operations (such as multiplication, division, etc), how would I do that? - Original Message - From: John W. Holmes [EMAIL PROTECTED] To: 'Stephen' [EMAIL PROTECTED]; 'Chris Wesley' [EMAIL PROTECTED] Cc: 'PHP List' [EMAIL PROTECTED] Sent: Wednesday, December 04, 2002 9:01 PM Subject: RE: [PHP] Looping Addition Let me explain this as best I can. The user enters how many numbers he wants to add. This form goes to another page. This page loops a form field and it's name is num and after num is the number it is currently on. Here's the code: form name=add method=post action=?php $_SERVER['PHP_SELF']; ? tr td width=35%How many numbers to add:/td tdinput name=vars type=text id=vars value=2 size=10 maxlength=2/td /tr tr td colspan=2div align=center input name=submit type=submit id=submit value=Next gt; /div/td /tr /form ?php } else { if(!is_numeric($_POST['vars']) || $_POST['vars'] = 1) { echo a href=\javascript:history.back(-1)\Go back/a and enter a number or something greater then 1. DO NOT enter a letter or symbol.; } else { ? form name=add action=module.php?id=?php echo $HTTP_GET_VARS['id']; ?show=calculate method=post input type=hidden name=vars value=?php echo $_POST['vars']; ? ?php $current = 1; do { ? tr td width=35%?php echo Number .$current.:; ?/td tdinput name=num?php echo $current; ? type=text id=vars value=0 size=25/td /tr ?php $current++; } while($current = $_POST['vars']) ? Change the above to: ?php for($x=0;$x$_POST['vars'];$x++) { ? tr td width=35%Number ?php echo $x; ?:/td tdinput name=num[] type=text id=vars value=0 size=25/td ?php } ? tr td colspan=2div align=center input name=add type=submit id=add value=Next gt; /div/td /tr /form This is only a snippet, there is more to it but for simplicities sake... Then I calculate it. My question is, how would I loop the adding? I hope you understand this now... And to do the addition... $sum = array_sum($_POST['num']); ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
One more question... If I then wanted to do this for the other operations (such as multiplication, division, etc), how would I do that? Assuming you've figured out how to do an array... You'll have to loop through the values like in the code that others posted. foreach($_POST['number'] as $num) { //calculate total here with $num } * = multiplication / = divide ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
So would I just put this? foreach(%_POST['number'] as $num) { $output *= $num; } echo $output; That's for multiplication. - Original Message - From: 1LT John W. Holmes [EMAIL PROTECTED] To: Stephen [EMAIL PROTECTED] Cc: PHP List [EMAIL PROTECTED] Sent: Thursday, December 05, 2002 8:24 AM Subject: Re: [PHP] Looping Addition One more question... If I then wanted to do this for the other operations (such as multiplication, division, etc), how would I do that? Assuming you've figured out how to do an array... You'll have to loop through the values like in the code that others posted. foreach($_POST['number'] as $num) { //calculate total here with $num } * = multiplication / = divide ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
On Thursday 05 December 2002 23:05, Stephen wrote: So would I just put this? foreach(%_POST['number'] as $num) { $output *= $num; } echo $output; That's for multiplication. Yes. Wouldn't it have been quicker for you to try it than to ask? BTW make sure that none of $num is zero. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* The longest part of the journey is said to be the passing of the gate. -- Marcus Terentius Varro */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
Continuing this even more...how would I use this same method only to subtract? What I'm doing right now would result in the following sitution. The user types in 5 as their first number. The second number is 4. Instead of returnin 1, it returns -9. It's subtracting the first number from 0, then taking 4 and subtracting that from -5. How can I fix this keeping in mind the user may type in more then two numbers? - Original Message - From: Chris Wesley [EMAIL PROTECTED] To: PHP List [EMAIL PROTECTED] Cc: Stephen [EMAIL PROTECTED] Sent: Wednesday, December 04, 2002 8:42 PM Subject: Re: [PHP] Looping Addition On Wed, 4 Dec 2002, Stephen wrote: This is only a snippet, there is more to it but for simplicities sake... Then I calculate it. My question is, how would I loop the adding? I hope you understand this now... Ah!, I think I understand better now. You want to add num1, num2, num3, ... numN, which are inputs from the second form in your sequence. Gotcha. If you name /all/ the form elements as nums[] instead of individually as num${current}, the numbers put into the form will all be accessible in one array to the PHP script that does the adding. Then you can just loop over the array of numbers. In your second form, change this: input name=num?php echo $current; ? type=text id=vars value=0 size=25 To this: input name=nums[] type=text id=vars value=0 size=25 Then in the script that adds the numbers: $total = 0; foreach( $_POST['nums'] as $number ){ $total += $number; } Hopefully I understood your problem this time! Let me know if I missed again. g.luck, ~Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
You simply need the absolute value of the difference. So taking Stephen's example below.. $total = 0; foreach( $_POST['nums'] as $number ) { $total -= $number;// if users inputs 5 as first value result equals -5 $total = abs($total); // result now equals 5 } - Original Message - From: Stephen [EMAIL PROTECTED] To: Chris Wesley [EMAIL PROTECTED] Cc: PHP List [EMAIL PROTECTED] Sent: Thursday, December 05, 2002 12:33 PM Subject: Re: [PHP] Looping Addition Continuing this even more...how would I use this same method only to subtract? What I'm doing right now would result in the following sitution. The user types in 5 as their first number. The second number is 4. Instead of returnin 1, it returns -9. It's subtracting the first number from 0, then taking 4 and subtracting that from -5. How can I fix this keeping in mind the user may type in more then two numbers? - Original Message - From: Chris Wesley [EMAIL PROTECTED] To: PHP List [EMAIL PROTECTED] Cc: Stephen [EMAIL PROTECTED] Sent: Wednesday, December 04, 2002 8:42 PM Subject: Re: [PHP] Looping Addition On Wed, 4 Dec 2002, Stephen wrote: This is only a snippet, there is more to it but for simplicities sake... Then I calculate it. My question is, how would I loop the adding? I hope you understand this now... Ah!, I think I understand better now. You want to add num1, num2, num3, ... numN, which are inputs from the second form in your sequence. Gotcha. If you name /all/ the form elements as nums[] instead of individually as num${current}, the numbers put into the form will all be accessible in one array to the PHP script that does the adding. Then you can just loop over the array of numbers. In your second form, change this: input name=num?php echo $current; ? type=text id=vars value=0 size=25 To this: input name=nums[] type=text id=vars value=0 size=25 Then in the script that adds the numbers: $total = 0; foreach( $_POST['nums'] as $number ){ $total += $number; } Hopefully I understood your problem this time! Let me know if I missed again. g.luck, ~Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
But then, if the user entered 5 - 6, it should be -1 but it'd return positive one... Is there another way? - Original Message - From: Kevin Stone [EMAIL PROTECTED] To: Stephen [EMAIL PROTECTED]; Chris Wesley [EMAIL PROTECTED] Cc: PHP List [EMAIL PROTECTED] Sent: Thursday, December 05, 2002 2:51 PM Subject: Re: [PHP] Looping Addition You simply need the absolute value of the difference. So taking Stephen's example below.. $total = 0; foreach( $_POST['nums'] as $number ) { $total -= $number;// if users inputs 5 as first value result equals -5 $total = abs($total); // result now equals 5 } - Original Message - From: Stephen [EMAIL PROTECTED] To: Chris Wesley [EMAIL PROTECTED] Cc: PHP List [EMAIL PROTECTED] Sent: Thursday, December 05, 2002 12:33 PM Subject: Re: [PHP] Looping Addition Continuing this even more...how would I use this same method only to subtract? What I'm doing right now would result in the following sitution. The user types in 5 as their first number. The second number is 4. Instead of returnin 1, it returns -9. It's subtracting the first number from 0, then taking 4 and subtracting that from -5. How can I fix this keeping in mind the user may type in more then two numbers? - Original Message - From: Chris Wesley [EMAIL PROTECTED] To: PHP List [EMAIL PROTECTED] Cc: Stephen [EMAIL PROTECTED] Sent: Wednesday, December 04, 2002 8:42 PM Subject: Re: [PHP] Looping Addition On Wed, 4 Dec 2002, Stephen wrote: This is only a snippet, there is more to it but for simplicities sake... Then I calculate it. My question is, how would I loop the adding? I hope you understand this now... Ah!, I think I understand better now. You want to add num1, num2, num3, ... numN, which are inputs from the second form in your sequence. Gotcha. If you name /all/ the form elements as nums[] instead of individually as num${current}, the numbers put into the form will all be accessible in one array to the PHP script that does the adding. Then you can just loop over the array of numbers. In your second form, change this: input name=num?php echo $current; ? type=text id=vars value=0 size=25 To this: input name=nums[] type=text id=vars value=0 size=25 Then in the script that adds the numbers: $total = 0; foreach( $_POST['nums'] as $number ){ $total += $number; } Hopefully I understood your problem this time! Let me know if I missed again. g.luck, ~Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
But then, if the user entered 5 - 6, it should be -1 but it'd return positive one... Is there another way? Come on, man... this is addition and subtraction. You can't figure it out? You simply need the absolute value of the difference. So taking Stephen's example below.. $total = 0; Look, right here, you're setting the total to zero, so now everything will be subtracted from zero. If you want everything to be subtracted from the first number, the set $total equal to the first number and loop through the remainder. $total = $_POST['nums'][0]; $cnt = count($_POST['nums']); for($x=1;$x$cnt;$x++) { $total -= $_POST['nums'][$x]; } And I'm sure your next post will be but how will I use that if I want to go back to addition/multiplication/division???; Here, assuming $mode can be set to add,sub,mul or div: $total = $_POST['nums'][0]; $cnt = count($_POST['nums']); for($x=1;$x$cnt;$x++) { switch($mode) { case add: $total += $_POST['nums'][$x]; break; case sub: $total -= $_POST['nums'][$x]; break; case mul: $total *= $_POST['nums'][$x]; break; case div: $total /= $_POST['nums'][$x]; break; } } echo $total; Plenty of other ways to do it, too, that may be more efficient. And I couldn't honestly tell you if *= and /= work and I don't want to go see. Hope that helps. Good luck. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
No, I wasn't going to ask that. But thanks for the info. :P - Original Message - From: 1LT John W. Holmes [EMAIL PROTECTED] To: Stephen [EMAIL PROTECTED]; Kevin Stone [EMAIL PROTECTED] Cc: PHP List [EMAIL PROTECTED] Sent: Thursday, December 05, 2002 3:14 PM Subject: Re: [PHP] Looping Addition But then, if the user entered 5 - 6, it should be -1 but it'd return positive one... Is there another way? Come on, man... this is addition and subtraction. You can't figure it out? You simply need the absolute value of the difference. So taking Stephen's example below.. $total = 0; Look, right here, you're setting the total to zero, so now everything will be subtracted from zero. If you want everything to be subtracted from the first number, the set $total equal to the first number and loop through the remainder. $total = $_POST['nums'][0]; $cnt = count($_POST['nums']); for($x=1;$x$cnt;$x++) { $total -= $_POST['nums'][$x]; } And I'm sure your next post will be but how will I use that if I want to go back to addition/multiplication/division???; Here, assuming $mode can be set to add,sub,mul or div: $total = $_POST['nums'][0]; $cnt = count($_POST['nums']); for($x=1;$x$cnt;$x++) { switch($mode) { case add: $total += $_POST['nums'][$x]; break; case sub: $total -= $_POST['nums'][$x]; break; case mul: $total *= $_POST['nums'][$x]; break; case div: $total /= $_POST['nums'][$x]; break; } } echo $total; Plenty of other ways to do it, too, that may be more efficient. And I couldn't honestly tell you if *= and /= work and I don't want to go see. Hope that helps. Good luck. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Looping Addition
Sorry for the uncontrolable emaling to the list but I'm in rather a stump. You may be hearing a lot from me over the next few days too. Anyway, I mentioned before my form with the addition that loops to the number of numbers the user wants to add. Now to the part of the actual addition, how could I loop that out also? Here's what I'm trying to do right now but naturally, it doesn't work: $output = 0; $current = 1; do { $output .= $num.$current + $current++; } while($current = $_POST['vars']); Any help would be great! Thanks! Thanks, Stephen Craton http://www.melchior.us What is a dreamer that cannot persevere? -- http://www.melchior.us -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
What type is $_POST['vars']? I think that it is a string...you might have to convert it to an integer... if( is_numeric( $_POST['vars'] ) ) { $vars = (int)$_POST['vars']; } else { echo Error: \$_POST['vars'] is not an integer.; } On Wed, 2002-12-04 at 14:26, Stephen wrote: Sorry for the uncontrolable emaling to the list but I'm in rather a stump. You may be hearing a lot from me over the next few days too. Anyway, I mentioned before my form with the addition that loops to the number of numbers the user wants to add. Now to the part of the actual addition, how could I loop that out also? Here's what I'm trying to do right now but naturally, it doesn't work: $output = 0; $current = 1; do { $output .= $num.$current + $current++; } while($current = $_POST['vars']); Any help would be great! Thanks! Thanks, Stephen Craton http://www.melchior.us What is a dreamer that cannot persevere? -- http://www.melchior.us __ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
I already have that. $_POST['vars'] is a number and I already check that you on a page before. All I need to know is how to keep adding numbers until there are no more to add... - Original Message - From: Ray Hunter [EMAIL PROTECTED] To: Stephen [EMAIL PROTECTED] Cc: PHP List [EMAIL PROTECTED] Sent: Wednesday, December 04, 2002 4:33 PM Subject: Re: [PHP] Looping Addition What type is $_POST['vars']? I think that it is a string...you might have to convert it to an integer... if( is_numeric( $_POST['vars'] ) ) { $vars = (int)$_POST['vars']; } else { echo Error: \$_POST['vars'] is not an integer.; } On Wed, 2002-12-04 at 14:26, Stephen wrote: Sorry for the uncontrolable emaling to the list but I'm in rather a stump. You may be hearing a lot from me over the next few days too. Anyway, I mentioned before my form with the addition that loops to the number of numbers the user wants to add. Now to the part of the actual addition, how could I loop that out also? Here's what I'm trying to do right now but naturally, it doesn't work: $output = 0; $current = 1; do { $output .= $num.$current + $current++; } while($current = $_POST['vars']); Any help would be great! Thanks! Thanks, Stephen Craton http://www.melchior.us What is a dreamer that cannot persevere? -- http://www.melchior.us __ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
On Wed, 4 Dec 2002, Stephen wrote: I already have that. $_POST['vars'] is a number and I already check that you on a page before. All I need to know is how to keep adding numbers until there are no more to add... If you mean that $_POST['vars'] is an array of numbers: $total = 0; foreach( $_POST['vars'] as $number ){ $total += $number; } If you mean that all vars in the POST data are numbers you want to add: $total = 0; foreach( $_POST as $number ){ $total += $number; } g.luck, ~Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
Let me explain this as best I can. The user enters how many numbers he wants to add. This form goes to another page. This page loops a form field and it's name is num and after num is the number it is currently on. Here's the code: form name=add method=post action=?php $_SERVER['PHP_SELF']; ? tr td width=35%How many numbers to add:/td tdinput name=vars type=text id=vars value=2 size=10 maxlength=2/td /tr tr td colspan=2div align=center input name=submit type=submit id=submit value=Next gt; /div/td /tr /form ?php } else { if(!is_numeric($_POST['vars']) || $_POST['vars'] = 1) { echo a href=\javascript:history.back(-1)\Go back/a and enter a number or something greater then 1. DO NOT enter a letter or symbol.; } else { ? form name=add action=module.php?id=?php echo $HTTP_GET_VARS['id']; ?show=calculate method=post input type=hidden name=vars value=?php echo $_POST['vars']; ? ?php $current = 1; do { ? tr td width=35%?php echo Number .$current.:; ?/td tdinput name=num?php echo $current; ? type=text id=vars value=0 size=25/td /tr ?php $current++; } while($current = $_POST['vars']) ? tr td colspan=2div align=center input name=add type=submit id=add value=Next gt; /div/td /tr /form This is only a snippet, there is more to it but for simplicities sake... Then I calculate it. My question is, how would I loop the adding? I hope you understand this now... - Original Message - From: Chris Wesley [EMAIL PROTECTED] To: PHP List [EMAIL PROTECTED] Cc: Stephen [EMAIL PROTECTED] Sent: Wednesday, December 04, 2002 7:44 PM Subject: Re: [PHP] Looping Addition On Wed, 4 Dec 2002, Stephen wrote: I already have that. $_POST['vars'] is a number and I already check that you on a page before. All I need to know is how to keep adding numbers until there are no more to add... If you mean that $_POST['vars'] is an array of numbers: $total = 0; foreach( $_POST['vars'] as $number ){ $total += $number; } If you mean that all vars in the POST data are numbers you want to add: $total = 0; foreach( $_POST as $number ){ $total += $number; } g.luck, ~Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
Hi, Thursday, December 5, 2002, 7:26:57 AM, you wrote: S Sorry for the uncontrolable emaling to the list but I'm in rather a stump. S You may be hearing a lot from me over the next few days too. S Anyway, I mentioned before my form with the addition that loops to the S number of numbers the user wants to add. Now to the part of the actual S addition, how could I loop that out also? S Here's what I'm trying to do right now but naturally, it doesn't work: S $output = 0; S $current = 1; S do S { S $output .= $num.$current + S $current++; S } while($current = $_POST['vars']); S Any help would be great! Thanks! S Thanks, S Stephen Craton S http://www.melchior.us S What is a dreamer that cannot persevere? -- http://www.melchior.us something like $output = 0; $current = 1; do { $x = 'num'.$current; if(isset($_POST[$x])){ $output += $_POST[$x]; } $current++; } while($current = $_POST['vars']); -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
On Wed, 4 Dec 2002, Stephen wrote: This is only a snippet, there is more to it but for simplicities sake... Then I calculate it. My question is, how would I loop the adding? I hope you understand this now... Ah!, I think I understand better now. You want to add num1, num2, num3, ... numN, which are inputs from the second form in your sequence. Gotcha. If you name /all/ the form elements as nums[] instead of individually as num${current}, the numbers put into the form will all be accessible in one array to the PHP script that does the adding. Then you can just loop over the array of numbers. In your second form, change this: input name=num?php echo $current; ? type=text id=vars value=0 size=25 To this: input name=nums[] type=text id=vars value=0 size=25 Then in the script that adds the numbers: $total = 0; foreach( $_POST['nums'] as $number ){ $total += $number; } Hopefully I understood your problem this time! Let me know if I missed again. g.luck, ~Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Looping Addition
Thank you! This is actually what I was wanting to do all along but I'm rather noobish when it comes to arrays. I can get by with them on MySQL and anything else, I suck at. Thanks again! - Original Message - From: Chris Wesley [EMAIL PROTECTED] To: PHP List [EMAIL PROTECTED] Cc: Stephen [EMAIL PROTECTED] Sent: Wednesday, December 04, 2002 8:42 PM Subject: Re: [PHP] Looping Addition On Wed, 4 Dec 2002, Stephen wrote: This is only a snippet, there is more to it but for simplicities sake... Then I calculate it. My question is, how would I loop the adding? I hope you understand this now... Ah!, I think I understand better now. You want to add num1, num2, num3, ... numN, which are inputs from the second form in your sequence. Gotcha. If you name /all/ the form elements as nums[] instead of individually as num${current}, the numbers put into the form will all be accessible in one array to the PHP script that does the adding. Then you can just loop over the array of numbers. In your second form, change this: input name=num?php echo $current; ? type=text id=vars value=0 size=25 To this: input name=nums[] type=text id=vars value=0 size=25 Then in the script that adds the numbers: $total = 0; foreach( $_POST['nums'] as $number ){ $total += $number; } Hopefully I understood your problem this time! Let me know if I missed again. g.luck, ~Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Looping Addition
Let me explain this as best I can. The user enters how many numbers he wants to add. This form goes to another page. This page loops a form field and it's name is num and after num is the number it is currently on. Here's the code: form name=add method=post action=?php $_SERVER['PHP_SELF']; ? tr td width=35%How many numbers to add:/td tdinput name=vars type=text id=vars value=2 size=10 maxlength=2/td /tr tr td colspan=2div align=center input name=submit type=submit id=submit value=Next gt; /div/td /tr /form ?php } else { if(!is_numeric($_POST['vars']) || $_POST['vars'] = 1) { echo a href=\javascript:history.back(-1)\Go back/a and enter a number or something greater then 1. DO NOT enter a letter or symbol.; } else { ? form name=add action=module.php?id=?php echo $HTTP_GET_VARS['id']; ?show=calculate method=post input type=hidden name=vars value=?php echo $_POST['vars']; ? ?php $current = 1; do { ? tr td width=35%?php echo Number .$current.:; ?/td tdinput name=num?php echo $current; ? type=text id=vars value=0 size=25/td /tr ?php $current++; } while($current = $_POST['vars']) ? Change the above to: ?php for($x=0;$x$_POST['vars'];$x++) { ? tr td width=35%Number ?php echo $x; ?:/td tdinput name=num[] type=text id=vars value=0 size=25/td ?php } ? tr td colspan=2div align=center input name=add type=submit id=add value=Next gt; /div/td /tr /form This is only a snippet, there is more to it but for simplicities sake... Then I calculate it. My question is, how would I loop the adding? I hope you understand this now... And to do the addition... $sum = array_sum($_POST['num']); ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php