ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Search problem in query

May 08, 2012 5:44am

Subscribe [1]
  • #1 / May 08, 2012 5:44am

    Franka

    54 posts

    Hai,
    I’m making a new website in EE 2.4 and having problems with search.
    I read I could do this search also in sql query. But I don’t get it working. Here’s my code:
    I’m a real beginner if it comes to query.

    <?php
    session_start();
    if($_POST)
    {
        // Sanitize POST data!    
        // Strip out all non alphanumeric characters except space, hyphen and underscore
    
        $ap_min = preg_replace('/[^a-zA-Z0-9_-\s]/','',$_POST['ap_min']);
        $ap_max = preg_replace('/[^a-zA-Z0-9_-\s]/','',$_POST['ap_max']);
    
        // Put everything in a session as we want to preserve this data for pagination
    
        $_SESSION['ap_min'] = $ap_min;
        $_SESSION['ap_max'] = $ap_max;
    }
    ?>
    
    {preload_replace:ap_min="<?php echo $_SESSION['ap_min'];?>"}
    {preload_replace:ap_max="<?php echo $_SESSION['ap_max'];?>"}
    
    vanaf: <em>{ap_min}</em>
    totenmet: <em>{ap_max}</em>
    
    gezocht aantal: <em>{ap_min} - {ap_max}</em>
    
    {!-- Search query --}
    
    {exp:query sql="SELECT min_ap, max_ap, sleep, za
    FROM vergaderlocatie 
    WHERE min_ap 
    BETWEEN {ap_min} AND {ap_max}
    AND
    WHERE max_ap
    BETWEEN {ap_min} AND {ap_max}
    AND
    WHERE sleep == {rooms}
    AND
    WHERE za
    BETWEEN {1} AND {azmax} " }
    
        {if count == 1}<ul>{/if}
            <li><a href="http://site/vergaderlocatie_resulaten">zoek</a></li>
        {if count > 0 && count == total_results}</ul>{/if}
    
    {/exp:query}

    I just have 4 searchfields to find if they are true:
    field 1: is the searchvalue between or equals my min and max values
    field 2: is the searchvalue between or equals my min and max values
    field 3: is the searchvalue equal or less my value
    field 4: yes or no

    Can I do this search like this. In the first part I make my search values numeric, my values in the data base are allready numeric.
    It’s a real simple website but I didn’t thought that a simple search would be so difficult in EE.
    Can someone help I’ve got the code from the example query page.

    thanks
    Franka

     

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases