Lisa23 Posted April 29, 2012 Share Posted April 29, 2012 Hi I have a form that is popluated from the database now I am trying to get the switch case to be based on the option the user selects is this possible to make a case a variable popluated by the drop down if so can someone show me what am i missing? the value I am trying to get from the form to the switch case is the ( $val->slug) but the value not been set help please here the form <form method="post"> <select name="deal-locations" onChange="this.form.submit()"> <?php while(list($key,$val) = each($locations)) { ?><option value="<?php echo $val->slug; ?>"><?php echo $val->slug; ?></option><?php } ?> </select> <input type="submit" value="submit"> </form> Here the switch case switch ($_POST['deal-locations']) { case " $val->slug": echo "<h3>deal-locations: ASC</h3>"; $args = array( 's' => $_GET['s'], 'post_type' => 'deals', 'deal-locations' => ' $val->slug', 'where' => ' $val->slug', 'paged' => 'paged' ); break; } Quote Link to comment https://forums.phpfreaks.com/topic/261786-how-can-i-get-the-value-of-a-switch-case-coming-from-the-drop-down-form/ Share on other sites More sharing options...
MMDE Posted April 29, 2012 Share Posted April 29, 2012 Sorry, but at least for me, this code made no sense... <?php echo $val->slug; ?> Here you want to echo the returned value of a function (without brackets) in an object you have created and assigned to the $val variable. switch ($_POST['deal-locations']) { case " $val->slug": echo "<h3>deal-locations: ASC</h3>"; $args = array( 's' => $_GET['s'], 'post_type' => 'deals', 'deal-locations' => ' $val->slug', 'where' => ' $val->slug', 'paged' => 'paged' ); break; } Same function call (without brackets) should equal $_POST['deal-locations']? Sorry if there is something I don't understand about this. I'm not an expert on OOP in PHP. Quote Link to comment https://forums.phpfreaks.com/topic/261786-how-can-i-get-the-value-of-a-switch-case-coming-from-the-drop-down-form/#findComment-1341519 Share on other sites More sharing options...
TOA Posted April 29, 2012 Share Posted April 29, 2012 @MMDE - most likely she's accessing a property. Quote Link to comment https://forums.phpfreaks.com/topic/261786-how-can-i-get-the-value-of-a-switch-case-coming-from-the-drop-down-form/#findComment-1341522 Share on other sites More sharing options...
Lisa23 Posted April 29, 2012 Author Share Posted April 29, 2012 HI thanks for all the help guys what I was trying to achieve was this, is working now I used the if statmenet instead. $val->slug = $_POST['deal-locations']; if($val->slug) { $args = array( 's' => $_GET['s'], 'post_type' => 'deals', 'deal-locations' => $val->slug, 'where' => $val->slug, 'paged' => 'paged'); echo "<h3> ".$val->slug."</h3>" ; } Quote Link to comment https://forums.phpfreaks.com/topic/261786-how-can-i-get-the-value-of-a-switch-case-coming-from-the-drop-down-form/#findComment-1341523 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.