Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-07-2005, 03:44 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Query Results for() while()

Hi, I'm trying to sort through the data to display 1 team at a time (while gathering tons of other information).

I need to get fc_team.managerid, fc_team.id, fc_team.playerid, fc_player_stats.score, fc_playerownership.playerid, fc_playerownership.roleid.

Table relations:
fc_team.id=fc_playerownership.teamid
fc_player_stats.playerid=fc_playerownership.player id

Field Info:
Each player in a given team will either have a roleid of 1-27, so for each team, there should be 27 players/results.

So basically I need to
PHP Code:
eval('$fantasy_cricket_teamplayerbit .= "' fetch_template('fantasy_cricket_teamplayerbit') . '";'); 
for each unique team, while gathering the scores for each player and have them calculated (there is some math involved here, not just addition) and the TOTAL calculated scores of all players added up and displayed per row along with the manager name.

So how should I do this? I tried using for() but that didn't help much, because I don't know how many rows to set the maximum (depends on the # of results from the query) the score selection messes this up, because it selects every player.

I know I have to use while() on the array, and for() afterwards, but I'm pretty stuck, so any help would be appreciated.
Reply With Quote
  #2  
Old 04-07-2005, 04:01 AM
WhSox21 WhSox21 is offline
 
Join Date: Feb 2004
Posts: 328
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not sure what exactly you need here but this is what you would do if I understand you correctly:

PHP Code:
while($row $DB_site->fetch_array($query_results))
{
  
// extra info here

Reply With Quote
  #3  
Old 04-07-2005, 05:20 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for reply

No I'm not that imcompetent, well not anymore anyway.

I need to only show my fantasy_cricket_teamplayerbit for every unique team, right now if I did while on the array, I would get a hundred or so results, depending on teams/players. Also to retrieve all the 'scores' of each player, then apply some math to them, then the final number I get by summing all the final numbers up, and show that total with each unique team.
Reply With Quote
  #4  
Old 04-07-2005, 06:09 PM
WhSox21 WhSox21 is offline
 
Join Date: Feb 2004
Posts: 328
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Add DISTINCT to your query. That will return every unique team. Other than that you'll need to fix your query to sum up everything.
Reply With Quote
  #5  
Old 04-07-2005, 09:59 PM
Link14716's Avatar
Link14716 Link14716 is offline
 
Join Date: Jun 2002
Location: Georgia, USA
Posts: 2,519
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Maybe something like this.
PHP Code:
$query mysql_query("....");
while (
$results mysql_fetch_array($query)) {
    
// Sort each row into the id.
    
$array[$results[id]]['rows'][] = $results;
    
// Other things not specific per row.
    
$array[$results[id]['blah'] = $result['blah']
}
// Go through each team.
foreach ($array as $id => $team) {
    
// Go through each row.
    
foreach ($team['rows'] as $row) {
        
// Do stuff here, like calculations and stuff.
    
}
    
// Finish doing team related things.
    
eval('$fantasy_cricket_teamplayerbit .= "' fetch_template('fantasy_cricket_teamplayerbit') . '";');

<3 foreach.
Reply With Quote
  #6  
Old 04-13-2005, 05:39 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Link, that worked.

Since I had to get this to work on a per match basis (game = parent) I threw a while(matchquery) around it. Then I threw each team into an array to display so I can get it to display what I need (but that works).

Well since I did that, somewhere along the way the part that seperates teams stopped working.

I'll post that section of the code, and the $array values in a link.

PHP Code:
while($teaminfo $DB_site->fetch_array($viewteams))
{
    
$array[$teaminfo[id]]['blah'] = $teaminfo['blah'];
    
$array[$teaminfo[id]]['rows'][] = $teaminfo;
}

// Process Each Team
foreach ($array as $id => $team)
{
    
// Process Each Player
    
foreach ($team['rows'] as $row)
    {
...   
    }
// calculations, etc

I'm pretty sure the blah stuff didn't affect it, anyway here are the 2 arrays.
http://world-a-team.com/aj/fantasy_c...id=20&show=yes
So everytime the roleid hits 27 and resets, it should be a new team.

** solved

thanks MarcoH64
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:16 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.04943 seconds
  • Memory Usage 2,225KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete