Jump to content

Drop Down Menu Validation Against Database


Kemik

Recommended Posts

Hello,

 

I want to do a query which selects the config.maps table.field WHERE ladder_id = $ladder_id. I can do this fine, but the next bit is slightly harder.

 

The maps are stored as an array, separated by commas. I can explode these commas to put the maps in to an array called $maps but how can I then check that a value inputted from the drop down menu matches one of these maps?

 

I cannot do:

 

if ($dropdown = $maps[1] || $dropdown = $maps[2] || $dropdown = $maps[3]) {

 

// Continue

 

}

 

As there could be anywhere between 1 and 5 or more maps in that array. Thanks for any help.

 

EDIT: Come to think about it, I don't even need to do another query, as I already done the query to populate the drop down menu. I just need to know how to compare the variable to the array now.

You're looking for the in_array function. In your case:

 

if (in_array($dropdown, $maps)){
// the value $dropdown has been found in array $maps
}

 

You could also do a foreach loop going through the array. Watch out with the example you used.

 

if ($dropdown = $maps[1] ||

 

Should be:

 

if ($dropdown == $maps[1] ||

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.