Book Image

Sphinx Search Beginner's Guide

By : Abbas Ali
Book Image

Sphinx Search Beginner's Guide

By: Abbas Ali

Overview of this book

Table of Contents (15 chapters)
Sphinx Search
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface

Time for action - creating the simple search form


  1. 1. Create a script /path/to/webroot/properties/index.php with the following content (this will be our home page):

    <?php
    /**
    * File: /path/to/webroot/properties/index.php
    */
    include('init.php');
    // Get the list of cities
    $query = "SELECT id, name FROM cities";
    foreach ($dbh->query($query) as $row) {
    $viewVars['cities'][$row['id']] = $row['name'];
    }
    // Get the query and city from form (if submitted)
    $q = !empty($_POST['q']) ? $_POST['q'] : '';
    $city = !empty($_POST['city_id']) ? $_POST['city_id'] : '';
    $viewVars['q'] = $q;
    $viewVars['city_id'] = $city;
    render('index');
    
  2. 2. Create the view for the form at /path/to/webroot/properties/views/index.thtml:

    <form action="index.php" method="post">
    <fieldset>
    <legend>Search</legend>
    <div class="input">
    <label>City: </label>
    <select name="city_id">
    <?php foreach ($viewVars['cities']
    as $id => $name): ?>
    <?php
    $selected = '';
    if ($id =...