pixeltrace Posted July 13, 2007 Share Posted July 13, 2007 hi, i need help. i currently have a code that assigns a value for $zoom depending on the value of $dist1 but its very long and i was thinking of just converting it to math that will add increments on the value of zoom with respect to the value of $dist1 my problem is, i dont know how to do it. below is my current code if ($dist1>=0) { if ($dist1<=600) { $zoom=4000; } } if ($dist1>=600) { if ($dist1<=1000) { $zoom=8500; } } if ($dist1>=1000) { if ($dist1<=1600) { $zoom=10000; } } if ($dist1>=1600) { if ($dist1<=2000) { $zoom=15000; } } if ($dist1>=2000) { if ($dist1<=3500) { $zoom=20000; } } if ($dist1>=3500) { if ($dist1<=4550) { $zoom=25000; } } if ($dist1>=4550) { if ($dist1<=5500) { $zoom=30000; } } if ($dist1>=5500) { if ($dist1<=6600) { $zoom=35000; } } if ($dist1>=6600) { if ($dist1<=7600) { $zoom=40000; } } if ($dist1>=7600) { if ($dist1<=8600) { $zoom=45000; } } if ($dist1>=8600) { if ($dist1<=9600) { $zoom=50000; } } if ($dist1>=9600) { if ($dist1<=10600) { $zoom=55000; } } if ($dist1>=10600) { if ($dist1<=11600) { $zoom=60000; } } if ($dist1>=11600) { if ($dist1<=12600) { $zoom=65000; } } if ($dist1>=12600) { if ($dist1<=13600) { $zoom=70000; } } if ($dist1>=13600) { if ($dist1<=14600) { $zoom=75000; } } if ($dist1>=14600) { if ($dist1<=15600) { $zoom=80000; } } if ($dist1>=15600) { if ($dist1<=16600) { $zoom=85000; } } if ($dist1>=16600) { $zoom=100000; } hope you could help me with this. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/ Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 i can't see the logical increase.. how are you working out the zoom compared to the dist! also it would probably be easier to do if ($dist1 >= 0 && $dist1<=600) { $zoom=4000; } if ($dist1 >= 601 && $dist1<=1000) { $zoom=8500; } quicker code being if ($dist1 >= 0 && $dist1<=600) { $zoom=4000; }else{ if ($dist1 >= 601 && $dist1<=1000) { $zoom=8500; } } Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-297160 Share on other sites More sharing options...
pixeltrace Posted July 13, 2007 Author Share Posted July 13, 2007 hi, The increase on the zoom will be 85% of the dist value let say i have dist = 1000 zoom value will be zoom = 8500 how do i do this? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-297163 Share on other sites More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 $zoom = $dist1*8.5 You're giving contradictory information, 85% of 1000 is 850 But I think this is what you mean. Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-297164 Share on other sites More sharing options...
pixeltrace Posted July 13, 2007 Author Share Posted July 13, 2007 also the values for my dist is 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 how to compute the zoom by 85% where dist is equal to those values? need help on this. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-297165 Share on other sites More sharing options...
pixeltrace Posted July 13, 2007 Author Share Posted July 13, 2007 hi, infid3l thanks you are right about it. sorry for the cofusion Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-297167 Share on other sites More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 hi, infid3l thanks you are right about it. sorry for the cofusion However, your statements have no real formula to them. You might be able to do something like: for($i=0;$i<=20*600;$i=$i+600){ if ($dist1>=$i) { if ($dist1<=($i+600)) { $zoom=($i+600)*4; break; } } } It doesn't exactly fulfill your "formula" though. Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-297169 Share on other sites More sharing options...
jitesh Posted July 13, 2007 Share Posted July 13, 2007 <?php $zoom_array = array(4000,8500,10000,15000); $range_array = array('0-600','601-1000','1001-1600','1601-2000'); $dist1 = 800; echo "This is the zoom value ".getzoom($dist1,$zoom_array,$range_array); function getzoom($dist1,$zoom_array,$range_array){ foreach($range_array as $key => $value){ $range = explode("-",$value); if($dist1 >= $range[0] and $dist1 <= $range[1]){ return $zoom_array[$key]; } } return "Nothing Found"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-297174 Share on other sites More sharing options...
pixeltrace Posted July 13, 2007 Author Share Posted July 13, 2007 thanks! i will try this Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-297199 Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 I love that idea jitesh, multidimensional array would be a little better but still love the idea:) nice work.. Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-297204 Share on other sites More sharing options...
pixeltrace Posted July 30, 2007 Author Share Posted July 30, 2007 hi, sorry i wasnt able to get back on this since the last reply. been busy on other projects im confused on the array... anyway, how can i just simplify this code? //computation for the scaling if ($distance >= 0 && $distance<=1000) { $scale=$distance*21; } if ($distance >= 1001 && $distance<=2000) { $scale=$distance*20; } if ($distance >= 2001 && $distance<=3000) { $scale=$distance*19; } if ($distance >= 3001 && $distance<=4000) { $scale=$distance*18; } if ($distance >= 4001 && $distance<=5000) { $scale=$distance*18; } if ($distance >= 5001 && $distance<=6000) { $scale=$distance*16; } if ($distance >= 6001 && $distance<=7000) { $scale=$distance*16; } if ($distance >= 7001 && $distance<=8000) { $scale=$distance*16; } if ($distance >= 8001 && $distance<=9000) { $scale=$distance*16; } if ($distance >= 9001 && $distance<=10000) { $scale=$distance*16; } hope you could help me with this. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-310754 Share on other sites More sharing options...
jitesh Posted July 30, 2007 Share Posted July 30, 2007 <?php $distance = 1500; $main_array = array("21-0-1000","20-1001-2000","19-2001-3000"); echo " Scal is ".getscale($main_array,$distance); function getscale($main_array,$distance){ foreach($main_array as $index => $n_arr_range){ $val_ar = array(); $val_ar = explode("-",$n_arr_range); if($distance >= $val_ar[1] and $distance <= $val_ar[2]){ return $distance*$val_ar[0]; } } return " Not Found "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-310764 Share on other sites More sharing options...
pixeltrace Posted July 30, 2007 Author Share Posted July 30, 2007 thanks! by the way, how do i get the value for $scale? since in my current code $scale=$distance*(multiplier) thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-310875 Share on other sites More sharing options...
pixeltrace Posted July 30, 2007 Author Share Posted July 30, 2007 this is what i did //computation for the scaling $main_array = array("21-0-1000","20-1001-2000","19-2001-3000","18-3001-4000","18-4001-5000","16-5001-6000","16-6001-7000","16-7001-8000","16-8001-9000","16-9000-10000"); //echo " Scal is ".getscale($main_array,$distance); function getscale($main_array,$distance){ foreach($main_array as $index => $n_arr_range){ $val_ar = array(); $val_ar = explode("-",$n_arr_range); if($distance >= $val_ar[1] and $distance <= $val_ar[2]){ return $distance*$val_ar[0]; $scale=$distance*$val_ar[0]; } } } and i am getting this error Fatal error: Cannot redeclare getscale() (previously declared in /var/www/html/myoochi/findit/propertyfindit.php:876) in /var/www/html/myoochi/findit/propertyfindit.php on line 876 hope you could help me with this. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-310881 Share on other sites More sharing options...
pixeltrace Posted July 30, 2007 Author Share Posted July 30, 2007 hi, any response on this? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-311489 Share on other sites More sharing options...
hitman6003 Posted July 30, 2007 Share Posted July 30, 2007 The error you are getting, "Cannot redeclare...", means that a function with that name already exists in the location specified. Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-311490 Share on other sites More sharing options...
jitesh Posted July 31, 2007 Share Posted July 31, 2007 //computation for the scaling $main_array = array("21-0-1000","20-1001-2000","19-2001-3000","18-3001-4000","18-4001-5000","16-5001-6000","16-6001-7000","16-7001-8000","16-8001-9000","16-9000-10000"); //echo " Scal is ".getscale_change($main_array,$distance); function getscale_change($main_array,$distance){ foreach($main_array as $index => $n_arr_range){ $val_ar = array(); $val_ar = explode("-",$n_arr_range); if($distance >= $val_ar[1] and $distance <= $val_ar[2]){ return $distance*$val_ar[0]; $scale=$distance*$val_ar[0]; } } } Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-311613 Share on other sites More sharing options...
pixeltrace Posted July 31, 2007 Author Share Posted July 31, 2007 hi, this is exactly the same code that i used but i am getting that error. how to fix it? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-311622 Share on other sites More sharing options...
jitesh Posted July 31, 2007 Share Posted July 31, 2007 Tried it ? check it again Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-311625 Share on other sites More sharing options...
pyrodude Posted July 31, 2007 Share Posted July 31, 2007 EDIT: Whoops. No clue. =) Quote Link to comment https://forums.phpfreaks.com/topic/59774-need-help-with-math-on-php/#findComment-311639 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.