simona6 Posted February 12, 2020 Share Posted February 12, 2020 if ($rowcats->followersrange == "2000-5000") { $lowrange2000 = "2000"; $lowestrange = $lowrange2000; $numberpeople = $rowcats->numberpeople; } if ($rowcats->followersrange == "5000-10000") { $lowrange5000 = "5000"; if ($lowrange5000 < $lowestrange) { $lowestrange = $lowrange5000; $numberpeople = $rowcats->numberpeople;} } if ($rowcats->followersrange == "10000-15000") { $lowrange10000 = "10000"; if ($lowrange10000 < $lowestrange) { $lowestrange = "$lowrange10000"; $numberpeople = $rowcats->numberpeople;} if ($lowestrange == NULL) { echo "yes";} echo "$lowestrange"; } if ($rowcats->followersrange == "15000-20000") { $lowrange15000 = "15000"; if ($lowrange15000 < $lowestrange) { $lowestrange = $lowrange15000;$numberpeople = $rowcats->numberpeople;} } We are trying to find the lowest range from the entries added to a database, so at the end, we can say the range is FROM... TO... They might opt for 2-5k, or 5-10k etc. If they opt for 10-15k, then the lowest range is 10,000. We have a result of 10000 - 15000. So the $lowrange10000 = "10000". Therefore, this should be echoing the $lowestrange from 7th line up in this code, but it remains at NULL, based on: $lowestrange = NULL;, set at the top of the code. Why is that? Quote Link to comment https://forums.phpfreaks.com/topic/310021-variable-not-changing-when-it-should-from-null/ Share on other sites More sharing options...
simona6 Posted February 12, 2020 Author Share Posted February 12, 2020 I have just set this at the top: $lowestrange = 50000; $highestrange = 500; It works, but is it the right thing to do. As 10000 is NOT lower than NULL...?! Quote Link to comment https://forums.phpfreaks.com/topic/310021-variable-not-changing-when-it-should-from-null/#findComment-1574232 Share on other sites More sharing options...
mconte Posted February 12, 2020 Share Posted February 12, 2020 (edited) 28 minutes ago, simona6 said: if ($rowcats->followersrange == "2000-5000") How is $rowcats->followersrange being set? Edited February 12, 2020 by mconte need to be specific Quote Link to comment https://forums.phpfreaks.com/topic/310021-variable-not-changing-when-it-should-from-null/#findComment-1574234 Share on other sites More sharing options...
simona6 Posted February 12, 2020 Author Share Posted February 12, 2020 At the top, as $followersrange = NULL; Quote Link to comment https://forums.phpfreaks.com/topic/310021-variable-not-changing-when-it-should-from-null/#findComment-1574235 Share on other sites More sharing options...
mconte Posted February 12, 2020 Share Posted February 12, 2020 (edited) 33 minutes ago, simona6 said: if ($rowcats->followersrange == "10000-15000") it'll only echo $lowestrange if this expression is evaluated as true... wait, can you show your code with your changes? Edited February 12, 2020 by mconte Quote Link to comment https://forums.phpfreaks.com/topic/310021-variable-not-changing-when-it-should-from-null/#findComment-1574236 Share on other sites More sharing options...
simona6 Posted February 12, 2020 Author Share Posted February 12, 2020 $lowestrange = 50000; $highestrange = 500; if ($rowcats->followersrange == "2000-5000") { $lowrange2000 = "2000"; $lowestrange = $lowrange2000; $numberpeople = $rowcats->numberpeople; } if ($rowcats->followersrange == "5000-10000") { $lowrange5000 = "5000"; if ($lowrange5000 < $lowestrange) { $lowestrange = $lowrange5000; $numberpeople = $rowcats->numberpeople;} } if ($rowcats->followersrange == "10000-15000") { $lowrange10000 = "10000"; if ($lowrange10000 < $lowestrange) { $lowestrange = "$lowrange10000"; $numberpeople = $rowcats->numberpeople;} } if ($rowcats->followersrange == "15000-20000") { $lowrange15000 = "15000"; if ($lowrange15000 < $lowestrange) { $lowestrange = $lowrange15000;$numberpeople = $rowcats->numberpeople;} } if ($rowcats->followersrange == "15000-20000") { $lowrange15000 = "15000"; if ($lowrange15000 < $lowestrange) { $lowestrange = $lowrange15000; $numberpeople = $rowcats->numberpeople;} } Though it was set to $lowestrange = NULL; before, at the top. Quote Link to comment https://forums.phpfreaks.com/topic/310021-variable-not-changing-when-it-should-from-null/#findComment-1574237 Share on other sites More sharing options...
mac_gyver Posted February 12, 2020 Share Posted February 12, 2020 if all you are doing is mapping input values to output values, don't write out conditional logic for every possible choice. if the input to output mapping doesn't contain any calculable relationship, define a data structure (array, database table) to map the input to the output. for the example values you have shown, wouldn't you just break apart the value at the '-' character and use the first part as the lowest range value? 1 Quote Link to comment https://forums.phpfreaks.com/topic/310021-variable-not-changing-when-it-should-from-null/#findComment-1574241 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.