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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.