vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   understanding "GROUP BY" (https://vborg.vbsupport.ru/showthread.php?t=103336)

Lionel 12-20-2005 12:07 AM

understanding "GROUP BY"
 
I've got 32 world cup teams separated in 8 groups of 4

I am trying to display them by group

But the below query returns only the last group. When I remove the GROUP BY clause, they all display

PHP Code:

$currentteams $DB_site->query("
SELECT *
        FROM " 
TABLE_PREFIX "cclpinternational_teams 
        WHERE disabled=1 AND name!='divadmin' AND division='
$thedivision
        GROUP BY 'groupname'
        ORDER BY name
        "
); 

What else one must know in order to get GROUP BY to display as needed?


I am really stucked. Can someone please give me a hint on how to proceed?
I managed the Group By clause to display how I wanted. However, while there is more than one element per group (in that case it should be four), it displays only one.


It consists of 8 groups with 4 teams each. I was hoping to be able to display all in same group together. I tried GROUP_CONCAT but that gives me an error.

Zubaz 12-21-2005 11:46 PM

GROUP BY is kind of a misnomer. It'll group your results, but not in a fashion that is useful outside of finding sums or average. What you're looking for is a complex ORDER BY I think.

Try changing your order clause to
Code:

ORDER BY `groupname`,`name`
This will sort by groupname, then by name within that.

Maybe I didn't get what you're trying to do, but I tried to do a lot of stuff like this before and you really can't with a single group by query.

Lionel 12-21-2005 11:50 PM

I got around it by displaying one group per page.

Zubaz 12-27-2005 11:52 PM

Your code needs to detect when the group changes since you're doing a per team call. You could call each of your groups, then call each team associated with it, but that's more queries.


All times are GMT. The time now is 10:09 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00984 seconds
  • Memory Usage 1,716KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete