EllisLab text mark
Advanced Search
     
Search problem in query
Posted: 08 May 2012 05:44 AM   [ Ignore ]
Avatar
Joined: 2010-09-29
81 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'];?>"}

<p>vanaf: <em>{ap_min}</em></p>
<
p>totenmet: <em>{ap_max}</em></p>

<
p>gezocht aantal: <em>{ap_min} {ap_max}</em></p>

{!-- 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="site/vergaderlocatie_resulaten">zoek</a></li>
    
{if count && 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