samedi 28 novembre 2015

Multiple Form checkbox results used in mysqli select

I want to integrate checkboxes with my SQL select statement but I'm not sure how to convert the array into a usable select.

    <form method="post">
    <input name="searchterm" type="search" placeholder="Enter Search Terms Here" />
    <input name="searchbtn" type="submit" value="Karaoke Search" />
    <input name="checkbx[]" type="checkbox" checked value="Chartbuster" />
      <label>Chartbuster</label>
    <input name="checkbx[]" type="checkbox" checked value="Sound Choice" />
      <label>Sound Choice</label>
    <input name="checkbx[]" type="checkbox" checked value="DKKaraoke" />
      <label>DKKaraoke</label>
    <input name="checkbx[]" type="checkbox" checked value="Sunfly" />
      <label>Sunfly</label>
    <input name="checkbx[]" type="checkbox" checked value="Karaoke Hits" />
      <label>Karaoke Hits</label>
    <?php
      if(isset($_POST['searchterm']) and ($_POST['searchterm']!="")) {
        $searchterm=($_POST['searchterm']);
        $checkbx=($_POST['checkbx']);
        $searchresults=$db->query("SELECT *
                                   FROM 1KaraokeDJ
                                   WHERE Artist LIKE '%$searchterm%'
                                     AND Brand IN $checkbx
                                   GROUP BY Artist,
                                            Title,
                                            Brand  
                                   ORDER BY Artist,
                                            Title,
                                            Disc LIMIT 100");
      }
    ...
    ?>
     ...
</form>

Basically, limit the search where Brand in one of the selected checkboxes




Aucun commentaire:

Enregistrer un commentaire