Jump to content

Modifying some PHP


Chaosmaster

Recommended Posts

Well I am a relative noob with this stuff, but I have this code I am trying to edit and its causing me a whole bunch of trouble

Basically I play WoW and run EQDKP, now as part of managing points we are trying to implement a system that takes points earned (from a certain area) * attendance percent to give us a usable point amount.


Here is the  code

[quote]$thirty_days = mktime(0, 0, 0, date('m'), date('d')-30, date('Y'));
$sql = "select ra.raid_id, count(ra.raid_id) raidSize, raid_name, raid_date  from " .RAID_ATTENDEES_TABLE. " ra
inner join " .RAIDS_TABLE. " r on ra.raid_id=r.raid_id WHERE
r.raid_date BETWEEN ".$thirty_days." AND ".time() . " [color=orange]AND r.raid_name = 'Naxxramas' OR 'AhnQiraj'[/color]
GROUP BY ra.raid_id
HAVING raidSize > 20";[/quote]

I changed this much to reflect the different areas I wanted it to pull the data from.

But i am not sure how to add something to reflect usable points, now I did try to add ROUND((member_current * member_attendance_percent),2) AS member usable  but then that just gives me an error on line 90 and 93 like this

Warning: array_keys(): The first argument should be an array in /www/relentless_sty_dk/wwwroot/dkp/listattendance.php on line 90

Warning: Invalid argument supplied for foreach() in /www/relentless_sty_dk/wwwroot/dkp/listattendance.php on line 93

any help would be appreciated, i am including the listattendance.php and the html document in the post

[code]<?php
/******************************
* EQdkp
* Copyright 2002-2005
* Licensed under the GNU GPL.  See COPYING for full terms.
* ------------------
* listmembers.php
* begin: Wed December 18 2002
*
* $Id: listmembers.php,v 1.46 2005/05/16 12:22:12 thundarr Exp $
*
******************************/

define('EQDKP_INC', true);
$eqdkp_root_path = './';
include_once($eqdkp_root_path . 'common.php');

$user->check_auth('u_member_list');

$cur_hash = hash_filename("listattendance.php");

// Find 30 days ago, then find how many raids occurred in those 30 days
// Do the same for 60 and 90 days
$thirty_days = mktime(0, 0, 0, date('m'), date('d')-30, date('Y'));
$sql = "select ra.raid_id, count(ra.raid_id) raidSize, raid_name, raid_date  from " .RAID_ATTENDEES_TABLE. " ra
inner join " .RAIDS_TABLE. " r on ra.raid_id=r.raid_id WHERE
r.raid_date BETWEEN ".$thirty_days." AND ".time() . " AND r.raid_name = 'Naxxramas' OR 'AhnQiraj'
GROUP BY ra.raid_id
HAVING raidSize > 20";

//echo "<pre>$sql</pre>";

$result = $db->query($sql);
$raids = Array();
$raid_sum = 0;
while ( $row = $db->fetch_record($result) ) {
$raids[] = $row["raid_id"];
$raid_sum+=$row["raidSize"];
}

$raid_count_30 = count($raids);
$raid_set = implode(",", $raids);
$raid_avg_size = $raid_sum/$raid_count_30;   
//$raid_count_30 = $db->query_first("SELECT count(*) FROM " . RAIDS_TABLE . "
// WHERE raid_date BETWEEN ".$thirty_days." AND ".time());
   
// Build an SQL query that includes each of the compare IDs
$sql = "SELECT m.member_name, count(m.member_name) AS member_attendance,
    (count(m.member_name)/" .$raid_count_30. ") AS member_attendance_percent,
    c.class_name AS member_class,
            ROUND((member_earned-member_spent+member_adjustment),2) AS member_current,
member_earned, m.member_id, ROUND(member_current*member_attendance_percent) AS member_use
    FROM " . MEMBERS_TABLE . " m
    INNER JOIN " .CLASS_TABLE. " c on m.member_class_id = c.class_id
            INNER JOIN " .RAID_ATTENDEES_TABLE. " ra on m.member_name=ra.member_name
    INNER JOIN " .RAIDS_TABLE. " r on ra.raid_id=r.raid_id
            WHERE (r.raid_date BETWEEN ".$thirty_days.' AND '.time().')' . "
          AND r.raid_id in (" . $raid_set . ")
    GROUP BY m.member_name
    ORDER BY c.class_id, member_attendance DESC";
//     ,concat(\"viewmember.php?s=" . $cur_hash . "&name=\", m.member_name) AS member_url
//echo "<pre>$sql</pre>";
$result = $db->query($sql);
//echo "Total Raids(over last 30 days): " . $raid_count_30;
while ( $row = $db->fetch_record($result) ) {
// echo "<pre>========\n";
// print_r($row);
// echo "</pre>";
$counts[$row['member_class']]['count']++;
$counts[$row['member_class']]['attendance']+=$row['member_attendance'];
$counts[$row['member_class']]['attendance_p']+=round($row['member_attendance_percent']*100);
$counts[$row['member_class']]['earned']+=$row['member_earned'];
        $counts[$row['member_class']]['current']+=$row['member_current'];

        $tpl->assign_block_vars('members_row_' . $row['member_class'], array(
            'ROW_CLASS'      => $eqdkp->switch_row_class(),
            'ID'              => $row['member_id'],
            'NAME'            => $row['member_name'],
            'CLASS'          => ( !empty($row['member_class']) ) ? $row['member_class'] : '&nbsp;',
            'EARNED'          => $row['member_earned'],
            'CURRENT'      => $row['member_current'],
            'C_CURRENT'      => color_item($row['member_current']),
            'RAIDS_30_DAYS' => $row['member_attendance'],
            'RAIDS_30_DAYS_P' => round($row['member_attendance_percent']*100),
            'C_RAIDS_30_DAYS' => color_item(round($row['member_attendance_percent']*100), true),
            'U_VIEW_MEMBER'  => 'viewmember.php'.$SID . '&amp;' . URI_NAME . '='.$row['member_name'])
        );
}

$ckeys = array_keys($counts);
$classAverages = Array();
$classAveragePerRaid = Array();
foreach($ckeys as $cur) {
if ($cur == "count") continue;
if ($counts[$cur]['count'] == 0) {
$classAverages['AVG_ATTENDANCE_' . $cur] = 0;
$classAverages['AVG_ATTENDANCE_P_' . $cur] = 0;
$classAverages['AVG_EARNED_' . $cur] = 0;
$classAverages['AVG_CURRENT_' . $cur] = 0;
}
else {
$classAverages['AVG_ATTENDANCE_' . $cur] = round($counts[$cur]['attendance']/$counts[$cur]['count']);
$classAverages['AVG_ATTENDANCE_P_' . $cur] = round($counts[$cur]['attendance_p']/$counts[$cur]['count']);
$classAverages['AVG_EARNED_' . $cur] = round($counts[$cur]['earned']/$counts[$cur]['count']);
$classAverages['AVG_CURRENT_' . $cur] = round($counts[$cur]['current']/$counts[$cur]['count']);
}
$classAverages['C_AVG_ATTENDANCE_' . $cur] = color_item($classAverages['AVG_ATTENDANCE_P_' . $cur]);
$classAverages['C_AVG_EARNED_' . $cur] = "positive";
$classAverages['C_AVG_CURRENT_' . $cur] = color_item($classAverages['AVG_CURRENT_' . $cur]);
        $tpl->assign_vars(array('AVG_PER_RAID_' . $cur => round($counts[$cur]['attendance']/$raid_count_30, 2)));
}
$tpl->assign_vars($classAverages);
// Now lets find the average per class

$tpl->assign_vars(array(
    'F_MEMBERS' => 'listmembers.php'.$SID,
    'V_SID'    => str_replace('?' . URI_SESSION . '=', '', $SID),
    'L_NAME'          => $user->lang['name'],
    'L_EARNED'        => $user->lang['earned'],
    'L_CURRENT'      => $user->lang['current'],
    'L_RAIDS_30_DAYS' => sprintf($user->lang['raids_x_days'], 30),
    'URI_ADDON'      => $uri_addon,
    'PAGE_HASH' => $cur_hash,
    'U_LIST_MEMBERS' => 'listmembers.php' . $SID . '&amp;',
    'U_RAIDS_30_DAYS' => $raid_count_30,
    'U_RAIDS_AVG_PPL' => round($raid_avg_size, 2) )
);

$eqdkp->set_vars(array(
    'page_title'    => sprintf($user->lang['title_prefix'], $eqdkp->config['guildtag'], $eqdkp->config['dkp_name']).': '.$user->lang['listmembers_title'],
    'template_file' => 'listattendance.html',
    'display'      => true)
);
[/code]

[attachment deleted by admin]
Link to comment
https://forums.phpfreaks.com/topic/28457-modifying-some-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.