lundi 3 avril 2017

How to pick up an array to run query in mysql using php

I am trying to create a system that displays a sport the user might want to play based on what they already play. The system will display the question "What sport do you play?" and give the user a number of options with checkboxes to choose the sports that they already play. When the user clicks the submit button the system will generate an answer based on what they have chosen. For example of the user picks basketball and rugby then the system will display football

I have started by creating an array to store each sport, I have also created a form with checkboxes.

<form action="#" method="post">
<input type="checkbox" name="check_list[]" value="Rugby"><label>Rugby</label><br/>
<input type="checkbox" name="check_list[]" value="Rootball"><label>Rootball</label><br/>
<input type="checkbox" name="check_list[]" value="PHP"><label>Basketball</label><br/>
<input type="submit" name="submit" value="Submit"/>
</form>

PHP

<?php

$my_array=array("Rugby","Football","BasketBall");

?>

I am possibly thinking of to check what array has been chosen (from checkbox) then running a query to check a database to see if it can find the same value and pick up a tagged value and display that information. Would this even work, if so how would I do it?

my database table looks like this.

Sports (table)

  • Sport_Id (PK)
  • Name
  • Tag

I want to have a function that picks up what has been clicked and displays the right information based on that. I have searched online for tutorials to help with this but I am unable to find any. I have been trying to work this out of months but have had no joy with it.




Aucun commentaire:

Enregistrer un commentaire