Jump to content

preg_match


Schlo_50

Recommended Posts

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

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

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

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 :D

 

Link to comment
https://forums.phpfreaks.com/topic/94162-preg_match/#findComment-482350
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.