Schlo_50 Posted March 3, 2008 Share Posted March 3, 2008 Hey all, I have an option select box which contains values, 20000, 30000, 50000 and 80000 representing yearly wages. <select name="select" class="form"> <option value="20000">Under £20k</option> <option value="30000">Under £30k</option> <option value="50000">Under £50k</option> <option value="80000">Under £80k</option> </select> When for example a user selects Under £20k I need my preg_match function to find and match all values less than '20000'. And so on and so forth for the larger values. How can i do this using: $subjectc = "$salary"; $wage = "/".$_POST['salary']."/i"; if (preg_match($wage, $subjectc){ Thanks for any help! Link to comment https://forums.phpfreaks.com/topic/94162-preg_match/ Share on other sites More sharing options...
trq Posted March 3, 2008 Share Posted March 3, 2008 Regular expressions are used to find patterns in strings, I'm not sure how this relates to your problem. What does $subjectc contain? Link to comment https://forums.phpfreaks.com/topic/94162-preg_match/#findComment-482328 Share on other sites More sharing options...
svivian Posted March 3, 2008 Share Posted March 3, 2008 Yeah no need for regular expressions at all. If you're just posting that form you'd need something like: $salary = $_POST['select']; // 'select' is the name you gave in the HTML if ( $salary == 20000 ) { // find stuff under 20k } else if ( $salary == 30000 ) { // find stuff under 30k } ...etc etc Link to comment https://forums.phpfreaks.com/topic/94162-preg_match/#findComment-482333 Share on other sites More sharing options...
Schlo_50 Posted March 3, 2008 Author Share Posted March 3, 2008 Cheers guys Link to comment https://forums.phpfreaks.com/topic/94162-preg_match/#findComment-482334 Share on other sites More sharing options...
Schlo_50 Posted March 3, 2008 Author Share Posted March 3, 2008 Would this work? if ($money == "20000"){ $subjectc = "20000"; }else{ if ($money == "30000"){ $subjectc = "30000"; }else{ if ($money == "50000"){ $subjectc = "50000"; }else{ if ($money == "80000"){ $subjectc = "80000"; } if (preg_match($jobtitle, $subject) && (preg_match($location, $subjectb) && ($salary == $subjectc))){ print_r ("$JOB_TITLE - $county<br />"); } Link to comment https://forums.phpfreaks.com/topic/94162-preg_match/#findComment-482341 Share on other sites More sharing options...
AV1611 Posted March 3, 2008 Share Posted March 3, 2008 it's salary <= '20000' if you do salary == '20000' it won't work unless you have a dropdown rather than a text entry. You prolly are using a dropdown, but I just thought I'd mention that cause you said: // find stuff under 20k which is won't, it will only find exact match. Sorry for splitting hairs Link to comment https://forums.phpfreaks.com/topic/94162-preg_match/#findComment-482350 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.