Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am working on a website for a hotel management company. On the portfolio page, I currently have a Google map with all of the hotels pinpointed and a table of the hotels all coming from a database. However, I want a form with checkboxes that correspond to the hotel brands. Selecting a checkbox will show only hotels that are that brand name. I can figure out how to do it with just one brand selected, but not with multiple.

This is the code for the form:

<form>
<div class="form-block">
<input type="checkbox" name="Courtyard" value="true" <?php if (isset($_GET["Courtyard"])) { echo "checked"; } ?> /> Courtyard<br />
<input type="checkbox" name="HolidayInnExpress" value="true" <?php if (isset($_GET["HolidayInnExpress"])) { echo "checked"; } ?> /> Holiday Inn Express<br />
<input type="checkbox" name="BestWestern" value="true" <?php if (isset($_GET["BestWestern"])) { echo "checked"; } ?> /> Best Western<br />
</div>
<div class="form-block">
<input type="checkbox" name="CrownePlaza" value="true" <?php if (isset($_GET["CrownePlaza"])) { echo "checked"; } ?> /> Crowne Plaza<br />
<input type="checkbox" name="HolidayInn" value="true" <?php if (isset($_GET["HolidayInn"])) { echo "checked"; } ?> /> Holiday Inn<br />
<input type="checkbox" name="SpringhillSuites" value="true" <?php if (isset($_GET["SpringhillSuites"])) { echo "checked"; } ?> /> Springhill Suites<br />
</div>
<div class="form-block">
<input type="checkbox" name="HamptonInn" value="true" <?php if (isset($_GET["HamptonInn"])) { echo "checked"; } ?> /> Hampton Inn<br />
<input type="checkbox" name="HomewoodSuites" value="true" <?php if (isset($_GET["HomewoodSuites"])) { echo "checked"; } ?> /> Homewood Suites<br />
<input type="checkbox" name="Independent" value="true" <?php if (isset($_GET["Independent"])) { echo "checked"; } ?> /> Independent Properties<br />
</div>
<button type="submit">Filter</button>

And the MySQL Query to display the table

    <?php
if (isset($_GET["BestWestern"])) {
  echo "Brand=\"Best Western\"";
}
$result = mysql_query("SELECT Name, City, State, Website FROM markers WHERE Brand LIKE '%' ORDER BY City");
echo "<table border='1'>
<tr>
    <th>Hotel Name</th>
    <th>City</th>
    <th>State</th>
    <th>Website</th>
</tr>";
while($row = mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['Name'] . "</td>";
    echo "<td>" . $row['City'] . "</td>";
    echo "<td>" . $row['State'] . "</td>";
    echo "<td><a href='" . $row['Website'] . "'>Visit Website</a></td>";
    echo "</tr>";
}
echo "</table>";
?>

Any help would be appreciated.

share|improve this question
Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial. – thaJeztah Feb 13 at 21:11

Simplest method would be use an WHERE ... IN () query, instead of the LIKE. e.g.

$brands = array('Brand X', 'Brand Y');
$sql = "SELECT ... WHERE Brand in ('" . implode("','", $brands) . "');";

Please note that this just an example. It is vulnerable to SQL injection attacks and should NOT BE USED as-is.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.