• hazzdude

    (@hazzdude)


    Hi there WP community, I hope that someone can help me out on a matter that has left me scratching my head for weeks!

    The website I am designing is for an estate agency using the Vebra Properties plugin. (The plugin chronologically adds properties from the vebra account to the SQL database) http://isvic.com/henrycharlesestates

    I need a searchbox on the website that will allow a search by the reference number of the property. In the database tables the reference numbers are listed in the column ‘agentref’ for example FA15 or LA175.

    In one of the plugin php files here is an example of it pulling the property types from the database and the property types are in the column ‘property_type’:

    function vp_get_property_types($mytype = "checkbox") {
        global $wpdb;
        global $vp_searchvars;    
    
        $table_name = $wpdb->prefix."vebraproperties";
        $sql = "SELECT DISTINCT property_type FROM $table_name WHERE 1=1";
        if ($vp_searchvars['branchid']!="") $sql.=" AND branchid=".$vp_searchvars['branchid'];
        if ($vp_searchvars['area']!="") $sql.=" AND area='".$vp_searchvars['area']."'";
        $sql.=" ORDER BY property_type";
        if ($mytype=="select") echo "<select name='type' id='vp_property_type'><option value=''>All</option>";
    
        if ($result = $wpdb->get_results($sql)) {
            foreach ($result as $vtype) {
                if (in_array($vtype->property_type,explode(",",$vp_searchvars['type']))) {
                    if ($mytype=="select")
                        echo "<option value='".$vtype->property_type."' selected='selected' />".$vtype->property_type."</option>";
                    else
                        echo "<input type='checkbox' name='type[]' value='".$vtype->property_type."' checked='checked' /><label>".$vtype->property_type."</label>";
                } else {
                    if ($mytype=="select")
                        echo "<option value='".$vtype->property_type."' />".$vtype->property_type."</option>";
                    else
                        echo "<input type='checkbox' name='type[]' value='".$vtype->property_type."' /><label>".$vtype->property_type."</label>";
                }
            }
        }
        if ($mytype=="select") echo "</select>";
    }

    If anyone could help me out that would be a great help!

The topic ‘Adding a search that will pull results from database’ is closed to new replies.