hello
D6, views2
to explain my problem will take some time, so be patient ;)
i have a taxonomy and it´s about fish ---> genus, species, subspecies, population.
on one site i want people to search after fishkeepers, so i made exposed filters where you can enter one or all of the terms (genus, species, subspecies, population).
if you view the site (without searching) then you get the exposed filters and below all fishkeepers. the problem is, if someone has 2 fish, then he is listed 2 times ... 10 fish - his name is 10x in the list
a guy, who i know wrote a code to remove double entries:
$users = array();
$usernames = array();
echo count($rows).'
';
foreach ($rows as $key => $row) {
if (!in_array($row['name'], $usernames)) {
$users[$key] = $row;
$usernames[] = $row['name'];
}
}
unset($usernames);
this works and you see every fishkeeper only one time, BUT :)
if you set in views, that you want 25 users / page then you get the wrong amount users per page, because views get a "wrong number". the user is listed 1 time, if he has 10 fish, then it counts 10 and this is what the "pageviewer" gets
the solution is to add the mySQL command "Group by users.name", but there is no way to set this in views.
can anyone help? i hope you understand my bad english :)
best wishes
markus

Comments
Bump...
Just leaving a comment in order to track this thread as I too am interested in how to inject additional custom SQL into a View entry.
When you edit your View in
When you edit your View in the GUI, look in the Basic Settings area and try setting the Distinct value to Yes. That might be what you're looking for.
The Boise Drupal Guy!
Distinct is set to YES
distinct is set to yes, doesn´t work
it is set in both displays - default and page
www.multivitamedia.at
www.ding-dong.at
www.breeders-international.com
Your last comment about
Your last comment about "there is no way to do this in views" is actually incorrect. You can use hook_views_query_alter to add a GROUP BY clause before the query is run in a custom module.
I've done something similar to this before.
Dave
Bingo!
Thanks dwees, I knew the wisdom was out there somewhere :)
thanks, worked for me too
thanks, worked for me too :)
www.multivitamedia.at
www.multivitamedia.at
www.ding-dong.at
www.breeders-international.com
little problem since
little problem since views-update to 2.3
i had a little script running for groupbyuser
<?php
function groupbyuser_views_query_alter(&$view, &$query) {
// add groupby
if ($view->name == 'myview') {
$query->groupby[] = 'users_name';
}
}
and after the update the script doesn´t work - does anyone know why?
greets
www.multivitamedia.at
www.ding-dong.at
www.breeders-international.com
Maybe the alias for the user
Maybe the alias for the user name field changed somehow? Try debugging the view and see if that's what happened.
Dave
hi how can i debug this?
hi
how can i debug this? i´m a screendesigner and not a coder, i got this script from a coder
greets
www.multivitamedia.at
www.ding-dong.at
www.breeders-international.com
Try using
Try using this:
<?php
function groupbyuser_views_query_alter(&$view, &$query) {
// add groupby
if ($view->name == 'myview') {
drupal_set_message('<pre>' . print_r($query, TRUE) . '</pre>');
$query->groupby[] = 'users_name';
}
}
?>
This should spit out the entire query in a reasonably formatted way, which you can try and analyze yourself, or post back here.
Dave
hi thanks, this works
hi
thanks, this works great
you can see the output at http://drupalbin.com/8360
users_name still exists ... and i saw, that the groupby array is empty
greets
www.multivitamedia.at
www.ding-dong.at
www.breeders-international.com
Yeah if you reorder the two
Yeah if you reorder the two lines inside the if() then statement, the group_by array should have your new addition. Not sure why it won't work then, seems like a bug to me? Try searching the issue queue for Views 2.3 and if you don't see your problem, describe it in detail there. I'm out of ideas.
Dave
hi ok, thanks for your
hi
ok, thanks for your help
greets
www.multivitamedia.at
www.ding-dong.at
www.breeders-international.com
Behaviour of adding GROUP BY changed since 2.3?
See this commit
Looks like its no longer possible to arbitrarily add single group by clauses like this?