Hi guys so i am trying to understand what the best way to search through a database using check boxes is. I am new to this and was looking at tutorials etc but cant seem to find anything which will help. I can make a search engine which searchs through my database and returns what i need but i dont get how to do it with checkboxes. For example:
My database contains this:
MovieName: ...
Gen1: ...
Gen2:...
Gen3:...
Gen4:...
etc
Now like i said above i got it to work with a search box where the user can write a simple phase such as action and it will bring up the movies which has action in their genres but i got no idea how to do it with checkboxes.
HTML:
<form action = "movie.php" method = "post">
<input type="checkbox" name = "search" value="action" checked> Kale<br>
<input type="checkbox" name= "search" value="comdey" checked> orange<br>
<input type="submit" value="Submit">
</form>
<?php echo("$output");?>
My database name TestHere and table is called test. Any help on completing this matter or any advice would be great, if you would like to see my search function i could post that but i dont think it will help with the search function of the checkboxes
Edit : This is a search function i created. Also i know its the old mysql shizzle but this is for a project which i am currently working on and i want it to be using that.
PHP:
$output = '';
//collect
if(isset($_POST['search'])){
$searchq = $_POST['search'];
$query = mysql_query("SELECT * FROM test WHERE movieName LIKE '%$searchq%' OR gen1 LIKE '%$searchq%' OR gen2 LIKE '%$searchq%' OR gen3 LIKE '%$searchq%' OR gen4 LIKE '%$searchq%'") or die("Could not search.");
$count = mysql_num_rows($query);
if($count == 0) {
$output = 'There was mo match!';
}else{
while($row = mysql_fetch_array($query)){
$rN = $row['movieName'];
$rI1 = $row['gen1'];
$rI2 = $row['gen2'];
$rI3 = $row['gen3'];
$rI4 = $row['gen4'];
$pic = $row['pix'];
$output .= '
<div class="panel panel-default">
<div class="panel-heading"><b>' . htmlentities($rN, ENT_QUOTES) . '</b></div>
<div class="panel-body">
<div class="pull-left col-xs-12 col-sm-4">
<a href="#">
<img class="img-thumbnail img-responsive" <img src="data:image/jpeg;base64,'.base64_encode( $pic ).'"/>
</a>
<a class="btn btn-success btn-block btnrec" href="#">View Recipe</a>
</div>
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="media-body">
<h3 class="media-heading">INGREDIENTS:</h3> ';
for( $i=1; $i < 7; $i++ )
{
if( ${"rI$i"} )
{
$output .= '
<div class="food-graph">
<span class="food-graph-title">' . htmlentities(${"rI$i"}, ENT_QUOTES) . '</span>
</div>
';
}
}
$output .= ' </div>
</div>
</div>
<div class="panel-footer">Rating</div>
</div>
';
}
}
}
Again this works perfectly for a search function, just not sure how i can apply this to a checkbox function :)
Aucun commentaire:
Enregistrer un commentaire