PHP Web Host - Quality Web Hosting For All PHP Applications Clan Themes! We make clans look good!!
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
Donovan
Client


Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Mon Jan 15, 2007 2:28 pm Reply with quote Back to top

I have several teams in a table defined by team_id. Each team may have several records in this table with a resource point defined by r_points equaling anywhere from 5 to -5.

Code:

$sql = $db->sql_query("SELECT * FROM " . $prefix . "_tc_ladderteams tclt
JOIN " . $prefix . "_tc_teams tct ON (tclt.team_id = tct.team_id)   
LEFT JOIN " . $prefix . "_eto_territories et ON (tct.tid = et.tid)   
LEFT JOIN " . $prefix . "_eto_divisions ed ON (tct.div_id = ed.div_id)
JOIN " . $prefix . "_tc_ladders tcl ON (tclt.ladder_id = tcl.sid)
WHERE enabled = 1 AND (ed.div_commander = '$nukeusername' || ed.div_xo ='$nukeusername')
ORDER BY 'name'");


I then need to SUM the resource points for each team and display

Code:

while ( $row = $db->sql_fetchrow($sql) ) {
         $team_id = $row['team_id'];
         $team_name= $row['name'];
         $t_name= $row['t_name'];
$result4 = $db->sql_query ("SELECT SUM(lkup.r_points) as resourcepoints
FROM ".$prefix."_eto_rpoints_lkup lkup
JOIN ".$prefix."_tc_teams tct
WHERE lkup.team_id = tct.team_id
AND (lkup.rp_id = '4' OR lkup.rp_id = '5')");
$info4 = $db->sql_fetchrow($result4);
$totalpoints += $info4['resourcepoints'];
         
    echo"<tr>"   
   . "<td align=\"center\" bgcolor=\"#666666\"><font color=\"#000000\">$team_name</font></td>"   
   . "<td align=\"center\" bgcolor=\"#666666\"><font color=\"#000000\">$totalpoints</font></td>"
   . "<td align=\"center\" bgcolor=\"#666666\"><font color=\"#000000\">$t_name</font></td>"
   . "<td align=\"center\" bgcolor=\"#666666\"><font color=\"#000000\">[ <a href=\"modules.php?name=Campaign&amp;file=Reenforce&amp;team_id=$team_id\">" . _CLICK . "</a>]</td>"
   . "</tr>";
   }
   echo "</table>"


I know this query works as I've tested it several time.

My problem is displaying all teams in the table listed by teamname, totalpoints, then t_name.

What is happening is the first team may SUM to 3. The next team SUMS to 6 the next to 9, then 12, then 15 and so on.

What I need is some kind of subquery for each teams $totalpoints, but am unsure how to do it.
View user's profile Send private message Visit poster's website ICQ Number
Donovan
Client


Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Mon Jan 22, 2007 11:37 am Reply with quote Back to top

Still need help figureing this out. Do I need a For Next loop somewhere in the middle to SUM totalpoints for each team?
View user's profile Send private message Visit poster's website ICQ Number
technocrat
Life Cycles Becoming CPU Cycles


Joined: Jul 07, 2005
Posts: 511

PostPosted: Mon Jan 22, 2007 6:46 pm Reply with quote Back to top

So what you want is if the team name is different start the total points over again?
View user's profile Send private message
Donovan
Client


Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Mon Jan 22, 2007 6:52 pm Reply with quote Back to top

Yes. Totalpoints for each team.
View user's profile Send private message Visit poster's website ICQ Number
technocrat
Life Cycles Becoming CPU Cycles


Joined: Jul 07, 2005
Posts: 511

PostPosted: Tue Jan 23, 2007 10:06 am Reply with quote Back to top

So something like
Code:
$previous_team = ''; //<--------
  while ( $row = $db->sql_fetchrow($sql) ) {
         $team_id = $row['team_id'];
         $team_name= $row['name'];
         $t_name= $row['t_name'];
$result4 = $db->sql_query ("SELECT SUM(lkup.r_points) as resourcepoints
FROM ".$prefix."_eto_rpoints_lkup lkup
JOIN ".$prefix."_tc_teams tct
WHERE lkup.team_id = tct.team_id
AND (lkup.rp_id = '4' OR lkup.rp_id = '5')");
$info4 = $db->sql_fetchrow($result4);
if ($previous_team != $team_name) {//<--------
$totalpoints = $info4['resourcepoints'];//<--------
$previous_team = $team_name;//<--------
} else {//<--------
$totalpoints += $info4['resourcepoints'];//<--------
}//<--------

         
    echo"<tr>"   
   . "<td align=\"center\" bgcolor=\"#666666\"><font color=\"#000000\">$team_name</font></td>"   
   . "<td align=\"center\" bgcolor=\"#666666\"><font color=\"#000000\">$totalpoints</font></td>"
   . "<td align=\"center\" bgcolor=\"#666666\"><font color=\"#000000\">$t_name</font></td>"
   . "<td align=\"center\" bgcolor=\"#666666\"><font color=\"#000000\">[ <a href=\"modules.php?name=Campaign&amp;file=Reenforce&amp;team_id=$team_id\">" . _CLICK . "</a>]</td>"
   . "</tr>";
   }
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum