->sql not working when using dynamic variable

->sql not working when using dynamic variable

Restful Web ServicesRestful Web Services Posts: 187Questions: 44Answers: 2

Why does this work?

    $iChaletId = '216';
    
    $rawquery = "SELECT t_owneraccount.iChaletId, SUM(t_owneraccount.fTotal) AS fTotal_total FROM t_owneraccount WHERE t_owneraccount.iChaletId = $iChaletId GROUP BY t_owneraccount.iChaletId";

    // select data
    $fTotal = array();
    $fTotal = $db
        ->sql( $rawquery )
        ->fetchAll();
    
    return $fTotal;   

But this does not?

    $iChaletId = $data['t_chalet.iChaletId'];
    
    $rawquery = "SELECT t_owneraccount.iChaletId, SUM(t_owneraccount.fTotal) AS fTotal_total FROM t_owneraccount WHERE t_owneraccount.iChaletId = $iChaletId GROUP BY t_owneraccount.iChaletId";

    // select data
    $fTotal = array();
    $fTotal = $db
        ->sql( $rawquery )
        ->fetchAll();
    
    return $fTotal;   

If I echo $data['t_chalet.iChaletId'] it is the correct value.

This also works,

    $iChaletId = $data['t_chalet.iChaletId'];
    
    $rawquery = "SELECT t_owneraccount.iChaletId, SUM(t_owneraccount.fTotal) AS fTotal_total FROM t_owneraccount GROUP BY t_owneraccount.iChaletId";

    // select data
    $fTotal = array();
    $fTotal = $db
        ->sql( $rawquery )
        ->fetchAll();
    
    return $fTotal;    

I cannot understand it?

Answers

  • allanallan Posts: 47,757Questions: 1Answers: 6,828 Site admin

    Can you show me the result of:

    var_dump( $data );
    var_dump( $rawquery );
    

    if you insert those two lines at line 4 in your above example (that doesn't work)?

    Thanks,
    Allan

  • Restful Web ServicesRestful Web Services Posts: 187Questions: 44Answers: 2

    Hi Allan,

    I am pretty sure now that is is something to do with the SUM return an empty or null value.

    If I try:

    var_dump( $data );
    var_dump( $rawquery );
    

    At line 4 as you suggested nothing happens, the XHR request just stays on pending. I don't get an error back, I get no response at all.

    Chris

  • allanallan Posts: 47,757Questions: 1Answers: 6,828 Site admin

    Odd - have a look at the server's error logs. They might show why it is bombing.

    Allan

Sign In or Register to comment.