Thursday, October 28, 2010

Re: Complex SQL queries

On Oct 28, 1:51 pm, joe_90 <joe.warren.me...@gmail.com> wrote:
> > how is the xml error related to your use of query.
>
> Well, I think it is because the array that is coming back contains two
> sub-arrays:
>
> array(4) {
>   [0]=>
>   array(2) {
>     ["seatavail"]=>
>     array(5) {
>       ["ThtId"]=>
>       string(3) "500"
>       ["ShoId"]=>
>       string(3) "100"
>       ["PerTime"]=>
>       string(19) "2011-01-11 13:00:00"
>       ["SroID"]=>
>       string(1) "a"
>       ["firstUnused"]=>
>       string(1) "1"
>     }
>     [0]=>
>     array(1) {
>       ["lastUnused"]=>
>       string(2) "15"
>     }
>   }
>
> Which $xml->serialize($var); barfs on.

so it's only tangibly related to your query.

> I really just want to delete the second array, but I can't change the
> query as it is a necessary value for the HAVING clause.

why not just post process the array into the format you want.

>
> I'm trying to use afterFind to remove it, but struggling..

good luck, afterFind isn't going to be called except after ... find ;)

For your own info/understanding the array keys in db queries comes
from the db saying which table the field belongs to. In the case of
calculated or aliased fields, that's often going to be null/no table.
Therefore you want something like this:

function imadethis() {
$return = $this->query( /* incidentally you could use find for this
or infact any select but it doesn't change the result */ );
foreach ($return as &$row) {
$row['seatavail'] += $row[0];
unset ($row[0]);
}
return $return;
}

hth,

AD

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: