Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-06-2003, 10:52 AM   PM User | #1
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
subtracting from a number untill its equal to another number..

hey..
hmm ok as the title says.. ive searched on the net for any code on this.
i know i need to use a forloop but im unsure how, i never liked loops lol.
i have a val you lets call $val1 and another $val2 and $val3
and i need to do some kinda lop so that it keeps subtracting.. hmm lets say 50 from val1 untill it is equal to or less than $val2and once it is it gives you the final result as $val3.
any ideas?
thanks
P
sir pannels is offline   Reply With Quote
Old 02-06-2003, 11:28 AM   PM User | #2
jcma
New Coder

 
Join Date: Jan 2003
Location: Lisbon / Portugal
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
jcma is an unknown quantity at this point
PHP Code:
   $var1 X;
   
$var2 Y;
   
$var3 $var1;
   while(
$var3 $var2)
        
$var3 -=50;

   echo 
"var1 $var1<br>var2 $var2 <br>var3 $var3"
jcma is offline   Reply With Quote
Old 02-06-2003, 01:58 PM   PM User | #3
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
hey.
Thanks -
i put that r ight into a php file an dadded the <? ?> but i get a error on line 4.. any ideas?
sir pannels is offline   Reply With Quote
Old 02-06-2003, 02:04 PM   PM User | #4
jcma
New Coder

 
Join Date: Jan 2003
Location: Lisbon / Portugal
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
jcma is an unknown quantity at this point
Quote:
Originally posted by sir pannels
hey.
Thanks -
i put that r ight into a php file an dadded the <? ?> but i get a error on line 4.. any ideas?
try changing:
$var1 = X and $var2=Y to numbers, like $var1 = 1234 and $var2 = 12
jcma is offline   Reply With Quote
Old 02-06-2003, 02:06 PM   PM User | #5
sir pannels
Regular Coder

 
Join Date: Jun 2002
Posts: 905
Thanks: 23
Thanked 5 Times in 5 Posts
sir pannels is an unknown quantity at this point
i already tried that.... thats what i thought first off but it didnt make a defference.
should this work on all versions of php?
sir pannels is offline   Reply With Quote
Old 02-06-2003, 02:10 PM   PM User | #6
jcma
New Coder

 
Join Date: Jan 2003
Location: Lisbon / Portugal
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
jcma is an unknown quantity at this point
this works fine for me.

PHP Code:

<?php

   $var1 
251;
   
$var2 49;
   
$var3 $var1;
   while(
$var3 $var2)
        
$var3 -=50;

   echo 
"var1 $var1<br>var2 $var2 <br>var3 $var3";

?>
jcma is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 09:17 PM.


Advertisement
Log in to turn off these ads.