MargateSteve Posted November 8, 2010 Share Posted November 8, 2010 Sorry if this should be in the HTML forum but as it is relating to something I am trying to do with php I thought this was the right place! I am creating a search page and one of the columns has only two potential values, 'H' for Home Games and 'A' for Away Games. Using radio buttons I can get the search page to filter correctly but there will also be times, once there are a few more search options on there, when a search would want to show All Games. The current form I have is <form id="form1" name="form1" method="post" action="fixrestestsearch.php"> <p> <label for="OPP">OPP</label> <input type="text" name="OPP" id="OPP" /> <br /> <label> <input type="radio" name="HA" value="H" id="HA_0" /> Home</label> <br /> <label> <input type="radio" name="HA" value="A" id="HA_1" /> Away</label> <br /> <label> <input type="radio" name="HA" value="" id="HA_2" /> All</label> <br /> <br /> SUB <input type="submit" name="SUB" id="SUB" value="Submit" /> </p> </form> and the query in the results page contains WHERE team_name='$OPP' AND h_a='$HA' If either the 'Home' or 'Away' buttons are checked everything works fine. If I check the 'All' button nothing is returned as it is looking for blank cells. I have also tried using 'value="*"' but that did not work. Is there anything that I can put as the value of a radio button that would select all records or would it have to be something amended in the query on the results page? Thanks in advance Steve Quote Link to comment https://forums.phpfreaks.com/topic/218058-radio-buttons-on-a-php-search-page/ Share on other sites More sharing options...
ninedoors Posted November 8, 2010 Share Posted November 8, 2010 Test for the $_POST['HA'] value and only add it if they have chosen home or away. Make your HA value for the all games selection equal all. <label><input type="radio" name="HA" value="all" id="HA_2" />All</label> <?php $sql = "SELECT * FROM your_db WHERE team_name = '$OPP'"; if ($_POST['HA'] != 'all') $sql .= " AND h_a = '$HA'"; mysql_query($sql); ?> This is untested but you can add in the proper query using your query with this logic. Quote Link to comment https://forums.phpfreaks.com/topic/218058-radio-buttons-on-a-php-search-page/#findComment-1131779 Share on other sites More sharing options...
MargateSteve Posted November 8, 2010 Author Share Posted November 8, 2010 That works absolutely perfectly. Thanks a lot. There will be some more questions in my quest to build a useful search page but will post those in another thread.. Thanks again Steve Quote Link to comment https://forums.phpfreaks.com/topic/218058-radio-buttons-on-a-php-search-page/#findComment-1131836 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.