Using Group By

QuestionsUsing Group By
Cliff asked 6 years ago

I am having trouble using Group BY in my grid SELECT statement. It seems to work but I get spurious parts of the query appearing at the top of my output page such as: GROUP BY `downloadyear` , `downloadmonthnumber` DESC ORDER BY `downloadyear` DESC

I have tried using a view (tested and working):
$g->select_command = "SELECT * FROM vw_countdownloadsbymonth";

and I have tried putting the code directly into the grid as:

$g->select_command = " SELECT
YEAR(`tbldownloadhistory`.`downloaddate`) AS `downloadyear`,
MONTH(`tbldownloadhistory`.`downloaddate`) AS `downloadmonthnumber`,
MONTHNAME(`tbldownloadhistory`.`downloaddate`) AS `downloadmonth`,
COUNT(`tbldownloadhistory`.`idtbldownloadhistory`) AS `numberofdownloads`
FROM
`tbldownloadhistory`
WHERE
(NOT (`tbldownloadhistory`.`downloadIP` IN (SELECT
`tblexcludeip`.`excludeip`
FROM
`tblexcludeip`)))
GROUP BY `downloadyear` , `downloadmonthnumber`";

But the results are the same with the strange text being displayed on my web page. Does using Group By in the query cause problems with the grid?

Any suggestions please?

Thanks,

Cliff

2 Answers
Abu Ghufran answered 6 years ago

Make sure, you call '$g->render();' function before any HTML is rendered
(echo'd) to output, as it expect exact JSON format for ajax calls. You can echo the output of render() function to desired location in html.

Cliff answered 6 years ago

Yes, that was the problem. Thanks very much for your prompt response.
Cliff

Your Answer

6 + 10 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?