Cake way will be more like that (not 100% your need, just
explanation):

$criteria       = array();

if ($gender == "male") {
        $criteria['TableOne.gender']    = 'Male';
}
elseif ($gender == "female") {
        $criteria['TableOne.gender']    = 'Female';
}
else {
        $criteria['TableOne.gender']    = 'IS NOT NULL';
}

if ($max_age && $min_age) {
        // free to you ton convert in years, month, ...
        $criteria['TableTwo.birth_date']        = "BETWEEN (" . date() . " -
{$min_age}) AND (" . date() . " - {$max_age})";
}

if ($status_swinger || $status_married || $status_inrelationship ||
$status_divorced || $status_single) {
        // sorry, don't understand why?
        //$select_sql = $select_sql. " AND ( ";
}

if ($status_single) {
        $criteria['TableTwo.status']    = $status_single;
        $testvar        = 1;
}

$result = $this->TableOne->findAll($criteria);

But if you still want you way:
// construct $select_sql like you did and
$this->TableOne->query($select_sql);

On 14 fév, 12:48, "anandrv" <[EMAIL PROTECTED]> wrote:
> How to search the query written in cake php.the query is too
> difficult
>
>         $select_sql = "SELECT * FROM `events_register` AS `table_one` ,
> `event_profileinform` AS `table_two`
>                                                 WHERE `table_one`.`id` = 
> `table_two`.`userid` ";
>                 if($gender == "male")
>                 {
>                         $select_sql = $select_sql. " AND `table_one`.`gender` 
> = 'Male' ";
>                 }
>
>                         else if($gender == "female")
>                         {
>                                 $select_sql = $select_sql. " AND 
> `table_one`.`gender` = 'Female'
> ";
>                         }
>
>                 else
>                 {
>                         $select_sql = $select_sql." AND `table_one`.`gender` 
> != '' ";
>                 }
>
>                 if ($max_age && $min_age)
>                 {
>                         $select_sql = $select_sql. " AND YEAR(CURDATE())-
> RIGHT( `table_two`.`birth_date` , 4 )  between $min_age and $max_age
> ";
>                 }
>
>                 if($status_swinger || $status_married || 
> $status_inrelationship ||
> $status_divorced || $status_single)
>                 {
>                         $select_sql = $select_sql. " AND ( ";
>                 }
>
>                 if($status_single)
>                 {
>                         $select_sql = $select_sql. " `table_two`.`status` =
> '$status_single' ";
>                         $testvar        = 1;
>                 }
> it is a normal php coding like that i need using cake php


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to