So I have my form and want to retrive all rows that has been checked off. But I can't get my LIKE to work as i want to.. It only works of one checkbox is checked off. I want to show all the rows that has each value. So if you check off "Rock" and "Jazz", it will show all the rows whit either "Rock" Or "Jazz". And that rows whit "Rock, Electronic" also will show up.
Should i have a different aproach to this?
<?php
if(isset($_POST['submit'])){
if (isset($_POST['genre'])) {
$genre_str = implode(",", $_POST['genre']);
$sql = $dbcon->prepare('SELECT * FROM user_profile WHERE user_genre LIKE :user_genre');
$sql->bindvalue(':user_genre', "%".$genre_str."%");
$sql->execute();
foreach ($sql as $row){
$row_id = htmlspecialchars($row['id']);
$row_genre = $row_post['user_genre'];
echo "id: " . $row_id . " = " . $row_genre;
echo "<br/>";
}
}
}
?>
<form action="" method="post">
<h4 class="text-center">Genre</h4>
<div class="checkbox">
<label class="checkbox-inline"><input type="checkbox" name="genre[]" value="Rock">Rock</label>
<label class="checkbox-inline"><input type="checkbox" name="genre[]" value="Funk">Funk</label>
</div>
<div class="checkbox">
<label class="checkbox-inline"><input type="checkbox" name="genre[]" value="Jazz">Jazz</label>
<label class="checkbox-inline"><input type="checkbox" name="genre[]" value="Hip-Hop">Hip-Hop</label>
</div>
<div class="checkbox">
<label class="checkbox-inline"><input type="checkbox" name="genre[]" value="Acoustic">Acoustic</label>
<label class="checkbox-inline"><input type="checkbox" name="genre[]" value="Electronic">Electronic</label>
</div>
<div class="col-md-12">
<input type="submit" name="submit" class="btn btn-block btn-success" value="Search">
</div>
</form>
Aucun commentaire:
Enregistrer un commentaire