le morte de bea arthur: "That's a pretty vague question. A select field and a couple of radio buttons is only going to give you a handful of $_POST variables when you submit the form.I know it's a vague question but I'm not sure how to explain it better.
What's in the select field? What do you want to do with it?"
if ($country == "United States") {
if ($radio == "male") { DO THIS }
else if
$radio == "female" { DO THIS }
else { DO THIS }
}le morte de bea arthur: "I think this will depend on what you plan to do with the data. Typically you'd take your two values (country and gender) and use those to produce a query on a database table or something."Oh, that's an idea.
le morte de bea arthur: "Again, I don't think you're giving enough information."The DO THIS is just changing a variable's value.
ook: " if you can be more specific about what happens in the "DO THIS" parts of your code, we might be able to suggest more concise or efficient ways of achieving it."
$lookupTable = array(
"USA" => array(
"male" => "CODE1",
"feamle" => "CODE2",
"null" => "CODE3"),
"Canada" => array(
"male" => "CODE4",
"female" => "CODE5",
"null" => "CODE6")
);
After that, you could access the codes by
$value = $lookupTable[$_POST['country'][$_POST['gender']];Note that PHP's syntax for defining huge arrays like this is kind of messy. That's likely by design, as it's generally frowned upon to hard-code large amounts of data into your app. It makes the code difficult to maintain.
schmod: "Your *real* best bet would be to create that multidimensional array by reading an external file or data source, or to write a function that queries that source directly. Parsing a .CSV file is a nice simple and lightweight option for your use case."That seems exactly what I was looking for. I haven't worked with multidimensional arrays before but now I can look them up!
What's in the select field? What do you want to do with it?
posted by le morte de bea arthur at 10:07 AM on April 4, 2012