Welcome, Guest
Username: Password: Remember me

TOPIC: DISTINCT grid layout

DISTINCT grid layout 05 Dec 2012 13:58 #5840

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
I have a table of defects that users are reported, but as a little offshoot, I am going to take all the names and numbers of people who have reported a fault and create a directory of users and reports.

I have already created the reporterdirectory layout, but am having problems ammending the query

case 'defects.reporterdirectory':
//BASE FIELDS
$query->select(
'DISTINCT a.number,'
. 'a.id,'
. 'a.depot,'
. 'a.name,'
. 'a.toc');
$this->addGroupBy('a.number'); //added by me
break;

Now if I feed in this query into PHP

SELECTDISTINCT a.number, a.id, a.depot, a.name, a.toc
FROM app01_traindefectlogger_defects AS a
WHERE (
a.published =1
OR a.published ISNULL
OR a.published =0
)
GROUPBY a.number

it returns the correct data.. but the altered MODEL above, the GROUPBY function is not functioning as antipated.

In the debugger, the query is being returned as

SELECT DISTINCT a.number,a.id,a.depot,a.name,a.toc
FROM app01_traindefectlogger_defects AS a
WHERE (a.published = 1 OR a.published IS NULL OR a.published = 0)
ORDER BY a.number,a.carriage asc

i.e it is NOT listing the GroupBy

How do I add an SQL GROUP BY function to the model so it mimics the SQL above. If you do not have the group by function, it just lists every record with multiple duplicates.
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
Last Edit: 05 Dec 2012 13:59 by MorganL.
The administrator has disabled public write access.

Re: DISTINCT grid layout 05 Dec 2012 14:27 #5841

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi Morgan,
case 'defects.reporterdirectory':
//BASE FIELDS
$query->select(
'DISTINCT a.number,'
. 'a.id,'
. 'a.depot,'
. 'a.name,'
. 'a.toc');
$this->addGroupBy('a.number'); //added by me
break;
You don't appear to have a WHERE clause in the query you've defined in your model...

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: DISTINCT grid layout 05 Dec 2012 14:29 #5843

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
How do I add an SQL GROUP BY function to the model so it mimics the SQL above
$query->addGroupBy
maybe off the top of my head???
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: DISTINCT grid layout 05 Dec 2012 15:04 #5851

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
  • Karma: 15
I thinjk the addGroupBy is used for the grid grouping layout and is reserved. I solved the problem with the following

$query->select(
'DISTINCT a.number,'
. 'a.id,'
. 'a.depot,'
. 'a.name,'
. 'a.toc');
$query->group('a.number');
break;
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Re: DISTINCT grid layout 07 Dec 2012 19:08 #5904

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
AddGroupBy is not the SQL group by statements, in facts...

It means that it is an ORDERING statement, by used as absolute priority.

Now, when you want to sort your columns, it is not breaking the grid group because the ordering value is setted after.

sorting acts in every different groups.

If you want to reorder the groups, instance the group value in the grid, and use it.
Then, you can retemplate for not having a repeated value in this column, but the sorting functionality is instancied.

I know it is off of topic, but can help anyway.
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy
Time to create page: 0.082 seconds

Get Started