Jump to content

Filtering an MySql query by radio button/check box


MargateSteve

Recommended Posts

Apologies for joining and then steaming straight in with a question but I am really struggling with a project that is running out of time!

I am redesigning my Football Clubs web site and want all the statistical side to be database driven. After struggling to get to grips with most of it I am currently resigned to putting them together in Excel and importing into the database via PHPMyAdmin just to get it up and running, but am struggling on some of the simpler points. I will only go through them one at a time though and can reassure everyone that I have searched high and low for the answers but am not sure exactly how the question needs to be asked ('using radio buttons to filter mysql query' is how I asked it), hence the fact that time is running out. So the first question (with apologies if it is not formatted/asked correctly!)......

 

I am running a query that shows a list of football matches that a player has featured in but want users to be able to choose what they actually see via a combination of radio buttons or check boxes.

 

For example, if someone wanted to see only 'Home' matches that the player scored a goal in they could check those two buttons and the table will filter, preferably in the same page. The final form will have a lot more than that but I just want to get a grasp first!

 

My query is

SELECT * FROM player_apps WHERE Player LIKE 'saund%' ORDER BY Year DESC, Month DESC, Day DESC

This one is for the page for a specific player (surname Saunders)

 

And the 'call is

 <?php do { ?>
          <tr>
            <td><?php echo $row_Recordset3['Day']; ?>/<?php echo $row_Recordset3['Month']; ?>/<?php echo $row_Recordset3['Year']; ?></td>
            <td><?php echo $row_Recordset3['H_A']; ?></td>
            <td><?php echo $row_Recordset3['Opponent']; ?></td>
            <td><?php echo $row_Recordset3['Comp']; ?></td>
            <td><?php echo $row_Recordset3['WDL']; ?></td>
            <td><?php echo $row_Recordset3['F']; ?> - <?php echo $row_Recordset3['A']; ?></td>
            <td><?php echo $row_Recordset3['Type']; ?></td>
            <td><?php echo $row_Recordset3['On']; ?></td>
            <td><?php echo $row_Recordset3['Off']; ?></td>
            <td><?php echo $row_Recordset3['MinsPlay']; ?></td>
            <td><?php echo $row_Recordset3['Goals']; ?></td>
            <td><?php echo $row_Recordset3['Assists']; ?></td>
            <td><?php echo $row_Recordset3['OwnGoals']; ?></td>
            <td><?php echo $row_Recordset3['Yellows']; ?></td>
            <td><?php echo $row_Recordset3['SentOff']; ?></td>
            <td><?php echo $row_Recordset3['Substituted By']; ?></td>
          </tr>
          <?php } while ($row_Recordset3 = mysql_fetch_assoc($Recordset3)); ?>

 

The basic form I have got is

<form id="form1" name="form1" method="post" action="">
  <p>
    <input type="radio" name="radio" id="All Games" value="All Games" />
    <label for="All Games">All Games</label>
    <input type="radio" name="radio" id="Home Games" value="Home Games" />
    <label for="Home Games">Home Games</label>
    <input type="radio" name="radio" id="Away Games" value="Away Games" />
    <label for="Away Games">Away Games</label>
    <br />
    <input type="radio" name="radio" id="Scored" value="Scored" />
    <label for="Scored">Scored</label>
    <input type="radio" name="radio" id="Did not Score" value="Did not Score" />
    <label for="Did not Score">Did not Score</label>
  </p>
</form>

 

All I need to do now is work out how to set it so that if the 'Home' radio button is checked it will only show records where the 'H_A' field has 'Home' in it, which I have found some code for elsewhere. However, if 'Home' and 'Scored' are both checked it would need to show records where the 'H_A' field has 'Home' in it and 'Goals' is >0.

 

I am very new php and mysql but as I am under a very tight schedule to get this done I am doing it all the wrong way round but hopefully if I can get it all up and running, I can improve it at a later date.

If anyone can help, point me to a simple tutorial or even suggest a better way then I would be extremely greatful!

 

Regards

Steve

Link to comment
Share on other sites

Yes that can be done. The radio button will send data in a name:value pair, and you can use the 'value' of 'name' as the fields used in your SELECT statement...avoid using *. Only send the query after the form has been submitted with the desired fields

 

Just my $.02

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.