Search the Community
Showing results for tags 'comparison'.
-
I want to compare two columns, essentially this: $query = "SELECT * FROM table WHERE column3 < column4;"; Is this even possible? Or have I just got the syntax badly wrong? I've tried writing out a complicated php code breaking my task into three MySQL lookups instead but that's proving more trouble than its worth.. Everything I've found on Google hasn't been related to my problem... Is anyone able to help me in the right direction? Thanks
-
I've never taken a logic class, or a CS class. This is likely very easy to anyone with any background in either topic. I have an array, $_SESSION['thresholds'], where I've given the array keys values such as "thresholdA", "thresholdB", "thresholdC", "thresholdD", etc. with corresponding elements that increase in value (5,15,50,75,etc.). They array is currently mapped in ascending order. I have a variable, $_SESSION['compare'], that I want to compare against all the elements in the $_SESSION['thresholds'] and, ultimately, I want to be able to echo/print the key of the largest array element that is less than the value of $_SESSION['compare']. Using the above values, if $_SESSION['compare'] == 21, then I would love to echo/print "thresholdB". What's the best method to accomplish this? Array_Walk? A switch statement? I first tried while() and was trying to use the pointer in the array, but I found that if I used next() to see if the next array element was larger, the actual use of next() within the while() statement caused the pointer to advance anyways. That seemed like the wrong path to take. The switch statement I've tried is failing, and I don't know how to use a comparison within an array_walk when I want to break out once the largest value is determined. This seems like such a basic function of array and variables but I'm struggling with this. Any advice would be much appreciated. Here's some of my tests that failed: reset($_SESSION['thresholds']); while( (current($_SESSION['compare']) < $_SESSION['thresholds']) and (key($_SESSION['thresholds']) <> 'thresholdMAX')) next($_SESSION['compare']); That final next() statement advances me one step too far. Should I use this and then backup one step? That might create problems of its own. Next I tried switch: switch ($_SESSION['compare']) { case ($_SESSION['compare'] >= $_SESSION['thresholds']['thresholdMAX']): $output = key($_SESSION['thresholds']['thresholdMAX']); break; case ($_SESSION['compare'] >= $_SESSION['thresholds']['thresholdD']): $output = key($_SESSION['thresholds']['thresholdD']); break; But that wasn't working and seems like the wrong way to go about this. Can anyone point me in the right direction? Thanks so much in advance!
- 3 replies
-
- beginner
- best practices
-
(and 3 more)
Tagged with: