views:

61

answers:

1

hello friends,
Any one please help me to convert this query into cakePHP find statement?

$sql = "select
                    categories.id
                FROM
                    categories
                WHERE
                    categories.competition_id='".$id."' AND ".
                    $logger['Competitor']['weight']. " between categories.weight_min and if(categories.weight_max>0,categories.weight_max,1000) AND ".
                    $logger['Competitor']['height']. " between categories.height_min and if(categories.height_max>0,categories.height_max,1000) AND ".
                    (date('Y')-  substr($logger['Competitor']['dateofbirth'],0,4 ))." between categories.age_min and if(categories.age_max>0,categories.age_max,100) AND \"".
                    $logger['Competitor']['gender']."\" = categories.gender AND ".
                    $logger['Competitor']['grade']." between categories.grade_from and if(categories.grade_to>0,categories.grade_to,100)
                ";
+3  A: 
'conditions' => array(
    'competition_id' => $id,
    intval($logger['Competitor']['weight']) . ' BETWEEN weight_min AND IF(weight_max > 0, weight_max, 1000)',
    intval($logger['Competitor']['height']) . ' BETWEEN height_min AND IF(height_max > 0, height_max, 1000)',
    intval(date('Y') - substr($logger['Competitor']['dateofbirth'], 0, 4)) . ' BETWEEN age_min AND IF(age_max > 0, age_max, 100)',
    'gender' => $logger['Competitor']['gender'],
    intval($logger['Competitor']['grade']) . ' BETWEEN grade_from AND IF(grade_to > 0, grade_to, 100)',
)
strager
You may have a few issues with the conditions with out implicit model references. For example, you may be required to put `'Category.competition_id' => $id` so the query connects the references correctly.
cdburgess