Jump to content

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] ||

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.