Jump to content

Radio Buttons on a php search page


MargateSteve

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.