I have researched for days for the best way to do this but I am stuck. I currently have a table in a database called ads.
In that table there is 7 columns.
id, venuename, imageurl, showingads, 2kandunder, 2kto4k, 4kandup.
The last 4 columns either have a "yes" or is left blank. I am currently using the script below to show only the rows in which showingads is "yes". I would like to keep it showing all rows with "yes" in showingads to start with, but would like to now add checkboxes to filter the 2kandunder, 2kto4k, 4kandup venues when clicked and allow multiple selections to be picked at once and display only the venues have a "yes" in the database for the options that are checked.
Can anyone show me an example of the best way to do this. Everything I found was making you press a submit button or was breaking up my WHERE showingads = 'yes'";
and adding the WHERE elsewhere after an array which prevents all of them from showing first. Help would be MUCH MUCH appreciated!!
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$sql = "SELECT id, venue, imageurl FROM ads WHERE `showingads` = 'yes'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<table class='tablebox' width='940' border='1' cellspacing='5'>
<tr><td width='75'>".$row["venue"]."</td></tr>
<tr>
<td width='10'><a href='post_click.php?id=".$row["id"]."'> <img src='".$row["imageurl"]."'></a></td>
</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
Aucun commentaire:
Enregistrer un commentaire