Filter content retrieved from database

Hi all,

I’m retrieving some content from a database. Would it be possible to use some check boxes to filter the results returned from the database? The user can select one or more check boxes according to his/her desired criteria.

My query starts with:

 $q = "SELECT m.messages, m.name, f.forum FROM messages AS m INNER JOIN forum AS f WHERE m.name = '$name'";
    $r = @mysqli_query($dbc, $q);

    $num = mysqli_num_rows($r);
    if ($num > 0) {
        $row = mysqli_fetch_array($r, MYSQLI_ASSOC);

        // echo html
    }   
<form method='post' action=''>
<input type='checkbox' name='option[affordable]' value=1>affordable	
<input type='checkbox' name='option[expensive]' value=1>expensive
<input type='checkbox' name='option[budget]' value=1>budget
<input type='submit' value='select'>
</form>
    

What would be the best way to go about it?

Thank you! :slight_smile:

foreach $_POST[‘option’] AS $key => $val
$query_where .= " AND “.$key.” = 1";

$q = “SELECT m.messages, m.name, f.forum FROM messages AS m INNER JOIN forum AS f WHERE m.name = ‘$name’”.$query_where;

Hi StarLion,

thank you for replying. I’ll try it out.