Question

can someone help me, and show me how to insert BEETWEN in having clausule in cakephp

exampleo of my codE:

$zaduzenja = $this->Zaduzenja->find('all',array(
                'conditions' => array(
                        'Zaduzenja.placeno' => 0 ),
                'fields' => array('Zaduzenja.obveznici_id', 'SUM(Zaduzenja.zaduzenje) as dug'),
                'group' => 'Zaduzenja.obveznici_id HAVING array(dug BETWEEN ? AND ? => array('.$iznosOd,$iznosDo)'

        ));

but this not working, i only want Calculated column "dug" to check if Dug >=$temp 1 AND Dug <=$temp2, but this is posible only in group with having clausule

Was it helpful?

Solution

why not simply this?

$db = $this->Zaduzenja->getDataSource();

$iznosOd = $db->value($iznosOd, 'double');  // quotes and escapes input to avoid SQL injections
$iznosDo = $db->value($iznosDo, 'double');  // ditto

$zaduzenja = $this->Zaduzenja->find(
    'all',
    array(
        'conditions' => array(
            'Zaduzenja.placeno' => 0 
        ),
        'fields' => array(
            'Zaduzenja.obveznici_id', 
            'SUM(Zaduzenja.zaduzenje) as dug'
        ),
        'group' => "Zaduzenja.obveznici_id HAVING dug BETWEEN $iznosOd AND $iznosDo"
    )
);

OTHER TIPS

Hi change your query as shown below:

$zaduzenja = $this->Zaduzenja->find('all',array(
                    'conditions' => array(
                            'Zaduzenja.placeno' => 0
                             ),
                    'fields' => array(
                            'Zaduzenja.obveznici_id',
                            'SUM(Zaduzenja.zaduzenje) as dug'
                            ),
                    'group' => 'Zaduzenja.obveznici_id having dug Between '.$temp_1.' and '.$temp2

            ));

Iinjoy

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top