romeshomey Posted November 17, 2006 Share Posted November 17, 2006 New member here, hello to everyone who was here before me.I am completely stumped here and hope someone can lead me in the right direction. My problem has to do with getting a $variable as a result of another $variable being greater than or less than a number.Say I have defined a variable through my MySQL query for instance:[code=php:0]sum($a+$b+$c) as $total [/code]How can I do something like this for example with my $total variable.[code=php:0]if $total < 15 = 10if $total > 15 but < 20 = 5if $total > 21 = -5as $newtotal[/code]Thanks in advance for any assistance. Link to comment https://forums.phpfreaks.com/topic/27551-mysqlphp-math-problem-greater-than-or-less-than-variable-problem/ Share on other sites More sharing options...
fenway Posted November 17, 2006 Share Posted November 17, 2006 Well, you case use a CASE statement for this -- but I'm confused by the use of php-style variables. Link to comment https://forums.phpfreaks.com/topic/27551-mysqlphp-math-problem-greater-than-or-less-than-variable-problem/#findComment-126070 Share on other sites More sharing options...
logansama Posted November 17, 2006 Share Posted November 17, 2006 I must agree with fenway, i am not sure what it is your trying to do ???Perhaps a CASE would work.[code=php:0]sum($a+$b+$c) as $total [/code]then..[code=php:0]switch($total) { case $total<15 : $newtotal= 10; break; ....etc}[/code]I guess its the same thing that fenway said?Perhaps this will help in some way. Link to comment https://forums.phpfreaks.com/topic/27551-mysqlphp-math-problem-greater-than-or-less-than-variable-problem/#findComment-126081 Share on other sites More sharing options...
fenway Posted November 17, 2006 Share Posted November 17, 2006 I meant an SQL case statement... Link to comment https://forums.phpfreaks.com/topic/27551-mysqlphp-math-problem-greater-than-or-less-than-variable-problem/#findComment-126391 Share on other sites More sharing options...
romeshomey Posted November 18, 2006 Author Share Posted November 18, 2006 Sorry, my question is PHP related, not MySQL. I think I figured it out though. I'll know in a bit lol.[code=php:0]if($total < 16) $total = 10;if(($total > 15)||($total < 21) $total = 5;if($total > 20) $total = $total - 5;[/code] Link to comment https://forums.phpfreaks.com/topic/27551-mysqlphp-math-problem-greater-than-or-less-than-variable-problem/#findComment-126592 Share on other sites More sharing options...
Zane Posted November 18, 2006 Share Posted November 18, 2006 So i'm assuming the 'newtotal' goes gets lower as the 'total' gets higherand from you're first example.....10 is the highest...newtotal will ever getso make $newtotal start at 10and decrement it gradually[code=php:0]$newtotal = 10;if ($total > 15) $newtotal -= 5;if($total > 21) $newtotal -= 5;echo $newtotal;[/code] Link to comment https://forums.phpfreaks.com/topic/27551-mysqlphp-math-problem-greater-than-or-less-than-variable-problem/#findComment-126597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.