n3mesis125 Posted April 30, 2008 Share Posted April 30, 2008 Hey everyone, I'm somewhat a newbie to php but I'm learning as I go and I'm doing well so far... i think I've pasted some code below which queries a mysql database to output information. However I'm trying to do a tree system with a huge list of topics i have in a table in the database called tracker_topics, there are about 570 topics. I read in all of the topics with a SELECT statement and then put them in an array so I can easily manipulate the information in foreach loops. However, each layer for sub topics I need to keep creating another foreach() loop and now I have about 4 of them. The problem is that the further i get nested, the longer the php script takes to run and some of the functions I use in previous loops no longer working in other loops, I just get a blank page pop up or sometimes a 'page cannot be displayed message. Hopefully someone is willing to go through some of the below code and let me know if there is an easier way to go about this to allow for quick loading and calculations. <?php include('..includes/sessions.inc'); require_once('../Connections/dbinfo.php'); mysql_select_db($database_db, $db); $servOff = $_SESSION['offset']; $shiftstart = date("Y-m-d", time() - $servOff); $prevDay = date("d", time() - $servOff)-1; $prevDate = date("Y-m-$prevDay"); $funcType = $_POST['func_type']; $main = $_POST['main_cat']; $GLOBALS['searchStr'] = ""; $qsub = "SELECT * FROM tracker_topics WHERE (cat_workgroup='all' OR cat_workgroup='$funcType') ORDER BY cat_name"; $rsub = mysql_query($qsub) or die(mysql_error()); $allTopics = array(); while ($row = mysql_fetch_array($rsub)) { $wg_i = explode(" ", $row['cat_children']); $child_list = ""; foreach ($wg_i as $w) { $chkGroup = exGroup($w); if ($chkGroup == 1) { $child_list .= $w . " "; } } $clFix_list = substr($child_list, 0, -1); $allTopics[] = array( 'name' => $row['cat_name'], 'tag' => $row['cat_tag'], 'children' => $row['cat_children'], 'group' => $clFix_list ); } function exGroup ($tag) { global $funcType; $ex_q = "SELECT * FROM tracker_topics WHERE cat_tag='$tag'"; $ex_r = mysql_query($ex_q); $ex_f = mysql_fetch_row($ex_r); $ex_w = $ex_f[6]; if ($ex_w == 'all' || $ex_w == $funcType) { return 1; } else { return 0; } } function searchTag($strVal) { global $allTopics; $GLOBALS['searchStr'] = $strVal; return array_filter($allTopics, 'findTag'); } function findTag($allTopics) { $tagVal = $GLOBALS['searchStr']; if ($allTopics['tag'] == $tagVal) { return $allTopics; } } $allCount = $allTopics; array_walk($allCount, 'doCount'); $out = "<tr><td colspan='12'><font color='#006699'>".strtoupper($main)." VOLUME</font>:<br /><br />"; $out .= "<input name='coll' id='coll' type='button' class='brbutt' onMouseOver='hov(this,\"brhov\")' onMouseOut='hov(this, \"brbutt\")' onClick='doColl();' value='Collapse All' /> <input name='exp' id='exp' type='button' class='brbutt' onMouseOver='hov(this,\"brhov\")' onMouseOut='hov(this, \"brbutt\")' onClick='doExpand();' value='Expand All' />"; $out .= "</td></tr>"; // Table Header Start $out .= "<tr>"; $out .= "<td colspan='2' width='427'> </td>"; $out .= "<td width='60' align='center'><font color='#006699'>% of<br/>Total</font></td>"; $out .= "<td width='60' align='center'><font color='#006699'>Perc<br/>Resolved</font></td>"; $out .= "<td width='60' align='center'><font color='#006699'>Today<br/>Count</font></td>"; $out .= "<td width='60' align='center'><font color='#006699'>Yestr<br/>Count</font></td>"; $out .= "<td width='60' align='center'><font color='#006699'>Variance<br/>%</font></td>"; $out .= "<td width='80' align='center'><font color='#006699'>Today<br/>AHT</font></td>"; $out .= "<td width='60' align='center'><font color='#006699'>Today<br/>Avg AHT</font></td>"; $out .= "<td width='80' align='center'><font color='#006699'>Yestr<br/>AHT</font></td>"; $out .= "<td width='60' align='center'><font color='#006699'>Yestr<br/>Avg AHT</font></td>"; $out .= "<td> </td>"; $out .= "</tr>"; $out .= "<tr><td colspan='12'><img src='../imgs/transp.gif' height='4' /></td></tr>"; // Table Header Finish function countType ($lob, $ctDay, $ctData) { if ($lob == 'cable') { $lob_str = 'cab_'; } if ($lob == 'common') { $lob_str = 'com_'; } if ($lob == 'internet') { $lob_str = 'int_'; } if ($lob == 'rhp') { $lob_str = 'rhp_'; } if ($lob == 'wireless') { $lob_str = 'wir_'; } if ($ctData == 'avg') { $data_str = 'avg_'; } if ($ctData == 'resY') { $data_str = 'resY_'; } if ($ctData == 'resN') { $data_str = 'resN_'; } if ($ctData == 'count') { $data_str = ''; } if ($ctDay == 'today') { $lob_end .= 't'; } if ($ctDay == 'prev') { $lob_end .= 'p'; } return $lob_str . $data_str . $lob_end; } $topic_width = "327"; $i=1; foreach ($allTopics as $key => $value) { $tag = $value['tag']; $name = $value['name']; $child = $value['children']; if (is_array($value)) { if ($tag == 'cable' || $tag == 'common' || $tag == 'internet' || $tag == 'rhp' || $tag == 'wireless') { $main_childArray = explode(" ", $child); $ctStr_T = countType($tag, 'today', 'count'); // Grab (today) count string to search allCount array $ctStr_P = countType($tag, 'prev', 'count'); // Grab (prev) count string to search allCount array $ctAvg_T = countType($tag, 'today', 'avg'); // Grab (today) average string to search allCount array $ctAvg_P = countType($tag, 'prev', 'avg'); // Grab (prev) average string to search allCount array $ctResY_T = countType($tag, 'today', 'resY'); // Grab (today) resolved (Y) string to search allCount array $ctResN_T = countType($tag, 'today', 'resN'); // Grab (today) resolved (N) string to search allCount array $main_aht_T = calcAHT($key, 'today'); $main_aht_P = calcAHT($key, 'prev'); $main_countT = calcCount($key, 'today'); $main_countP = calcCount($key, 'prev'); $main_items = count($main_childArray); $main_avg_aht_T = calcAvg($key, $main_items, 'today'); $main_avg_aht_P = calcAvg($key, $main_items, 'prev'); if ($child != "") { $main_format_name = "<div id='expand_id" .$i."_a' style='display: inline;'><a href='javascript:show_sub(\"" .$i. "_a\",\"open\");' class='trackrep_link' id='ah_".$i."_a'><b>" .$name. "</b></a></div>"; } else { $main_format_name = $name; } $out .= "<tr class='off' onmouseover='this.className=\"on\"' onmouseout='this.className=\"off\"'>"; $out .= "<td width='100'><font color='#006699'>Topic " . $i . "</font></td>"; // Topic Category # $out .= "<td align='left' valign='top' width='$topic_width'>" .$main_format_name. "</td>"; // Topic Name $out .= "<td align='center' width='60'></td>"; // Percent Total $out .= "<td align='center' width='60'>".calcResolve($key)."</td>"; // Resolve Percentage (Yes) $out .= "<td align='center' width='60'>".$main_countT."</td>"; // Today Count $out .= "<td align='center' width='60'>".$main_countP."</td>"; // Prev Count $out .= "<td align='center' width='60'>".calcVar($main_countT, $main_countP)."</td>"; // Variance $out .= "<td align='center' width='80'>".sec2hms($main_aht_T, true)."</td>"; // AHT Today $out .= "<td align='center' width='60'>".$main_avg_aht_T."</td>"; // AHT Today Average $out .= "<td align='center' width='80'>".sec2hms($main_aht_P, true)."</td>"; // AHT Previous $out .= "<td align='center' width='60'>".$main_avg_aht_P."</td>"; // AHT Previous Average $out .= "<td align='center' width='60'></td>"; // Spacer $out .= "</tr>"; // SUB 1 START -------------------------------------------------------------------------------------------------------- $out .= "<tr id='sub_id" .$i. "_a' style='display: none;'>"; $out .= "<td colspan='12'>"; $out .= "<table id='sub_table_id" .$i. "_a' cellpadding='0' cellspacing='0' border='0' class='main_text'>"; $sub1_items = count($sub1_childArray); $s1=0; foreach ($main_childArray as $sub1) { $sub1_info = searchTag($sub1); $sub1_key = getAttr($sub1_info, 'key'); $sub1_wg = getAttr($sub1_info, 'group'); $sub1_child = getAttr($sub1_info, 'children'); $sub1_childArray = explode(" ", $sub1_child); if ($sub1_child != "") { $sub1_name = getAttr($sub1_info, 'name'); $sub1_countT = calcCount($sub1_key, 'today'); $sub1_countP = calcCount($sub1_key, 'prev'); $sub1_aht_T = calcAHT($sub1_key, 'today'); $sub1_aht_P = calcAHT($sub1_key, 'prev'); $sub1_avg_aht_T = calcAvg($sub1_key, $sub1_items, 'today'); $sub1_avg_aht_P = calcAvg($sub1_key, $sub1_items, 'prev'); $sub1_perc_total = floor((($sub1_countT / $main_countT)*100)); if ($sub1_perc_total < 1) { $sub1_perc_total = "-"; } if ($sub1_child != "") { $sub1_format_name = "<div id='expand_id" .$i."_".$s1. "_b' style='display: inline;'><a href='javascript:show_sub(\"" .$i."_".$s1. "_b\",\"open\");' class='trsub_link' id='ah_".$i."_".$s1."_b'><b>" .$sub1_name. "</b></a></div>"; } else { $sub1_format_name = $sub1_name; } $sub1_spacer = " <img src='../imgs/sub_link.gif' align='absmiddle' /> "; $out .= "<tr class='off' onmouseover='this.className=\"on\"' onmouseout='this.className=\"off\"'>"; $out .= "<td width='100'><font color='#006699'>".$i.".".$s1."</font></td>"; // Topic Category # $out .= "<td align='left' valign='top' width='$topic_width'>".$sub1_spacer . $sub1_format_name. "</td>"; // Topic Name $out .= "<td align='center' width='60'>".$sub1_perc_total."</td>"; // Percent Total $out .= "<td align='center' width='60'>".calcResolve($sub1_key)."</td>"; // Resolve Percentage (Yes) $out .= "<td align='center' width='60'>".$sub1_countT."</td>"; // Today Count $out .= "<td align='center' width='60'>".$sub1_countP."</td>"; // Prev Count $out .= "<td align='center' width='60'>".calcVar($sub1_countT, $sub1_countP)."</td>"; // Variance $out .= "<td align='center' width='80'>".sec2hms($sub1_aht_T, true, 1)."</td>"; // AHT Today $out .= "<td align='center' width='60'>".$sub1_avg_aht_T."</td>"; // AHT Today Average $out .= "<td align='center' width='80'>".sec2hms($sub1_aht_P, true, 1)."</td>"; // AHT Previous $out .= "<td align='center' width='60'>".$sub1_avg_aht_P."</td>"; // AHT Previous Average $out .= "<td align='center' width='60'></td>"; // Spacer $out .= "</tr>"; // SUB 2 START -------------------------------------------------------------------------------------------------------- if ($sub1_child != "") { $out .= "<tr id='sub_id" .$i."_".$s1. "_b' style='display: none;'>"; $out .= "<td colspan='12'>"; $out .= "<table id='sub_table_id" .$i."_".$s1. "_b' cellpadding='0' cellspacing='0' border='0' class='main_text'>"; $sub2_items = count($sub2_childArray); $s2=0; foreach ($sub1_childArray as $sub2) { $sub2_info = searchTag($sub2); $sub2_key = getAttr($sub2_info, 'key'); $sub2_wg = getAttr($sub2_info, 'group'); $sub2_child = getAttr($sub2_info, 'children'); $sub2_childArray = explode(" ", $sub2_child); $sub2_name = getAttr($sub2_info, 'name'); $sub2_countT = calcCount($sub2_key, 'today'); $sub2_countP = calcCount($sub2_key, 'prev'); $sub2_aht_T = calcAHT($sub2_key, 'today'); $sub2_aht_P = calcAHT($sub2_key, 'prev'); $sub2_avg_aht_T = calcAvg($sub2_key, $sub2_items, 'today'); $sub2_avg_aht_P = calcAvg($sub2_key, $sub2_items, 'prev'); if ($sub2_child != "") { $sub2_format_name = "<div id='expand_id" .$i."_".$s1."_".$s2. "_c' style='display: inline;'><a href='javascript:show_sub(\"" .$i."_".$s1."_".$s2. "_c\",\"open\");' class='trackrep_link' id='ah_".$i."_".$s1."_".$s2."_c'><b>" .$sub2_name. "</b></a></div>"; } else { $sub2_format_name = $sub2_name; } $sub2_spacer = " <img src='../imgs/sub_link.gif' align='absmiddle' /> "; $out .= "<tr class='off' onmouseover='this.className=\"on\"' onmouseout='this.className=\"off\"'>"; $out .= "<td width='100'><font color='#006699'>- ".$i.".".$s1.".".$s2. "</font></td>"; // Topic Category # $out .= "<td align='left' valign='top' width='$topic_width'>".$sub2_spacer . $sub2_format_name. "</td>"; $out .= "<td align='center' width='60'></td>"; // Percent Total $out .= "<td align='center' width='60'></td>"; // Resolve Percentage (Yes) $out .= "<td align='center' width='60'>".$sub2_countT."</td>"; // Today Count $out .= "<td align='center' width='60'>".$sub2_countP."</td>"; // Prev Count $out .= "<td align='center' width='60'>".calcVar($sub2_countT, $sub2_countP)."</td>"; // Variance $out .= "<td align='center' width='80'>".sec2hms($sub2_aht_T, true, 1)."</td>"; // AHT Today $out .= "<td align='center' width='60'>".$sub2_avg_aht_T."</td>"; // AHT Today Average $out .= "<td align='center' width='80'>".sec2hms($sub2_aht_P, true, 1)."</td>"; // AHT Previous $out .= "<td align='center' width='60'>".$sub2_avg_aht_P."</td>"; // AHT Previous Average $out .= "<td align='center' width='60'></td>"; // Spacer $out .= "</tr>"; // SUB 3 START -------------------------------------------------------------------------------------------------------- if ($sub2_child != "") { $out .= "<tr id='sub_id" .$i."_".$s1."_".$s2. "_c' style='display: none;'>"; $out .= "<td colspan='12'>"; $out .= "<table id='sub_table_id" .$i."_".$s1."_".$s2. "_c`' cellpadding='0' cellspacing='0' border='0' class='main_text'>"; $sub3_items = count($sub2_childArray); $s3=0; foreach ($sub2_childArray as $sub3) { $sub3_info = searchTag($sub3); $sub3_index = array_keys($sub3_info); $sub3_key = $sub3_index[0]; $sub3_wg = $sub3_info[$sub3_key]['group']; $sub3_child = $sub3_info[$sub3_key]['children']; $sub3_childArray = explode(" ", $sub3_child); $sub3_name = $sub3_info[$sub3_key]['name']; $sub3_countT = $allCount[$sub3_key][$ctStr_T]; $sub3_countP = $allCount[$sub3_key][$ctStr_P]; $sub3_aht_T = $allCount[$sub3_key][$ctAvg_T]; $sub3_aht_P = $allCount[$sub3_key][$ctAvg_P]; $sub3_avg_aht_T = floor(($sub3_aht_T / $sub3_items)); $sub3_avg_aht_P = floor(($sub3_aht_P / $sub3_items)); if ($sub3_child != "") { $sub3_format_name = "<div id='expand_id" .$i."_".$s1."_".$s2."_".$s3. "_d' style='display: inline;'><a href='javascript:show_sub(\"" .$i."_".$s1."_".$s2."_".$s3. "_d\",\"open\");' class='trsub_link' id='ah_".$i."_".$s1."_".$s2."_".$s3."_d'><b>" .$sub3_name. "</b></a></div>"; } else { $sub3_format_name = $sub3_name; } $sub3_spacer = " <img src='../imgs/sub_link.gif' align='absmiddle' /> "; $out .= "<tr class='off' onmouseover='this.className=\"on\"' onmouseout='this.className=\"off\"'>"; $out .= "<td width='100'><font color='#006699'> - " .$i.".".$s1.".".$s2.".".$s3. "</font></td>"; // Topic Category # $out .= "<td align='left' valign='top' width='$topic_width'>".$sub3_spacer . $sub3_format_name. "</td>"; $out .= "<td align='center' width='60'></td>"; // Percent Total $out .= "<td align='center' width='60'></td>"; // Resolve Percentage (Yes) $out .= "<td align='center' width='60'>".$sub3_countT."</td>"; // Today Count $out .= "<td align='center' width='60'>".$sub3_countP."</td>"; // Prev Count $out .= "<td align='center' width='60'>".calcVar($sub3_countT, $sub3_countP)."</td>"; // Variance $out .= "<td align='center' width='80'>".sec2hms($sub3_aht_T, true, 1)."</td>"; // AHT Today $out .= "<td align='center' width='60'>".$sub3_avg_aht_T."</td>"; // AHT Today Average $out .= "<td align='center' width='80'>".sec2hms($sub3_aht_P, true, 1)."</td>"; // AHT Previous $out .= "<td align='center' width='60'>".$sub3_avg_aht_P."</td>"; // AHT Previous Average $out .= "<td align='center' width='60'></td>"; // Spacer $out .= "</tr>"; // SUB 4 START -------------------------------------------------------------------------------------------------------- if ($sub3_child != "") { $out .= "<tr id='sub_id" .$i."_".$s1."_".$s2."_".$s3. "_d' style='display: none;'>"; $out .= "<td colspan='12'>"; $out .= "<table id='sub_table_id" .$i."_".$s1."_".$s2."_".$s3. "_d`' cellpadding='0' cellspacing='0' border='0' class='main_text'>"; $sub4_items = count($sub3_childArray); $s4=0; foreach ($sub3_childArray as $sub4) { $sub4_info = searchTag($sub4); $sub4_index = array_keys($sub4_info); $sub4_key = $sub4_index[0]; $sub4_wg = $sub4_info[$sub4_key]['group']; $sub4_name = $sub4_info[$sub4_key]['name']; $sub4_countT = $allCount[$sub4_key][$ctStr_T]; $sub4_countP = $allCount[$sub4_key][$ctStr_P]; $sub4_aht_T = $allCount[$sub4_key][$ctAvg_T]; $sub4_aht_P = $allCount[$sub4_key][$ctAvg_P]; $sub4_avg_aht_T = floor(($sub4_aht_T / $sub4_items)); $sub4_avg_aht_P = floor(($sub4_aht_P / $sub4_items)); $sub4_spacer = " <img src='../imgs/sub_link.gif' align='absmiddle' /> "; $out .= "<tr class='off' onmouseover='this.className=\"on\"' onmouseout='this.className=\"off\"'>"; $out .= "<td width='100'><font color='#006699'> - " .$i.".".$s1.".".$s2.".".$s3.".".$s4. "</font></td>"; // Topic Category # $out .= "<td align='left' valign='top' width='$topic_width'>".$sub4_spacer . $sub4_name. "</td>"; $out .= "<td align='center' width='60'></td>"; // Percent Total $out .= "<td align='center' width='60'></td>"; // Resolve Percentage (Yes) $out .= "<td align='center' width='60'>".$sub4_countT."</td>"; // Today Count $out .= "<td align='center' width='60'>".$sub4_countP."</td>"; // Prev Count $out .= "<td align='center' width='60'>".calcVar($sub4_countT, $sub4_countP)."</td>"; // Variance $out .= "<td align='center' width='80'>".sec2hms($sub4_countT, true)."</td>"; // AHT Today $out .= "<td align='center' width='60'>".$sub4_avg_aht_T."</td>"; // AHT Today Average $out .= "<td align='center' width='80'>".sec2hms($sub4_countP, true)."</td>"; // AHT Previous $out .= "<td align='center' width='60'>".$sub4_avg_aht_P."</td>"; // AHT Previous Average $out .= "<td align='center' width='60'></td>"; // Spacer $out .= "</tr>"; $s4++; } $out .= "<tr><td colspan='12'> </td></tr>"; $out .= "</table>"; $out .= "</td>"; $out .= "</tr>"; } // SUB 4 END ---------------------------------------------------------------------------------------------------------- $s3++; } $out .= "<tr><td colspan='12'> </td></tr>"; $out .= "</table>"; $out .= "</td>"; $out .= "</tr>"; } // SUB 3 END ---------------------------------------------------------------------------------------------------------- $s2++; } $out .= "<tr><td colspan='12'> </td></tr>"; $out .= "</table>"; $out .= "</td>"; $out .= "</tr>"; } // SUB 2 END ---------------------------------------------------------------------------------------------------------- $s1++; } } $out .= "<tr><td colspan='12'> </td></tr>"; $out .= "</table>"; $out .= "</td>"; $out .= "</tr>"; // SUB 1 END ---------------------------------------------------------------------------------------------------------- $i++; } } } function getAttr ($gaArray, $grab) { $tagIndex = array_keys($gaArray); $tagKey = $tagIndex[0]; $tagAttr = $gaArray[$tagKey][$grab]; if ($grab == 'key') { return $tagKey; } else { return $tagAttr; } } function calcCount ($ccKey, $type) { global $allCount; global $ctStr_T; global $ctStr_P; if ($type == 'today') { $ccStr = $allCount[$ccKey][$ctStr_T]; } else { $ccStr = $allCount[$ccKey][$ctStr_P]; } return $ccStr; } function calcAHT ($ahtKey, $type) { global $allCount; global $ctAvg_T; global $ctAvg_P; if ($type == 'today') { $ahtStr = $allCount[$ahtKey][$ctAvg_T]; } else { $ahtStr = $allCount[$ahtKey][$ctAvg_P]; } return $ahtStr; } function calcAvg ($caKey, $caItems, $type) { global $allCount; global $ctAvg_T; global $ctAvg_P; if ($type == 'today') { $caStr = $allCount[$caKey][$ctAvg_T]; } else { $caStr = $allCount[$caKey][$ctAvg_P]; } $avg_calc = floor(($caStr / $caItems)); return $avg_calc; } function calcResolve ($crKey) { global $allCount; global $ctResY_T; global $ctResN_T; $yes = $allCount[$crKey][$ctResY_T]; $no = $allCount[$crKey][$ctResN_T]; $total = $yes + no; $div = $yes / $total; $formula = floor($div*100); return $formula; unset($yes, $no, $total, $div, $formula, $allCount, $ctResY_T, $ctResN_T); } function calcVar ($today, $prev) { if ($today > $prev) { $variance = (($today - $prev) / $today); $varCol = 'green'; } else if ($prev > $today) { $variance = (($prev - $today) / $prev); $varCol = 'red'; } $format_var = floor($variance*100); if ($format_var == 0) { $format_var = "-"; } return "<font color='$varCol'>" .$format_var. "</font>"; } function doCount (&$item1, $key) { global $shiftstart; global $prevDate; global $funcType; $iTag = $item1['tag']; $wir_t = 0; $rhp_t = 0; $com_t = 0; $cab_t = 0; $int_t = 0; // Today Count variables for all LOB $wir_p = 0; $rhp_p = 0; $com_p = 0; $cab_p = 0; $int_p = 0; // Previous Count variables for all LOB $wir_avg_t = 0; $rhp_avg_t = 0; $com_avg_t = 0; $cab_avg_t = 0; $int_avg_t = 0; // Today AVG variables for all LOB $wir_avg_p = 0; $rhp_avg_p = 0; $com_avg_p = 0; $cab_avg_p = 0; $int_avg_p = 0; // Previous AVG variables for all LOB $wir_resY_t = 0; $rhp_resY_t = 0; $com_resY_t = 0; $cab_resY_t = 0; $int_resY_t = 0; // Today Resolved (Yes) variables for all LOB $wir_resN_t = 0; $rhp_resN_t = 0; $com_resN_t = 0; $cab_resN_t = 0; $int_resN_t = 0; // Today Resolved (No) variables for all LOB //$wir_resY_p = 0; $rhp_resY_p = 0; $com_resY_p = 0; $cab_resY_p = 0; $int_resY_p = 0; // Previous Resolved (Yes) variables for all LOB //$wir_resN_p = 0; $rhp_resN_p = 0; $com_resN_p = 0; $cab_resN_p = 0; $int_resN_p = 0; // Previous Resolved (No) variables for all LOB $qhits = "SELECT * FROM `tracker_data` WHERE (cat_main='$iTag' OR cat_sub1='$iTag' OR cat_sub2='$iTag' OR cat_sub3='$iTag' OR cat_sub4='$iTag' OR cat_sub5='$iTag') AND (`date`='$shiftstart' OR `date`='$prevDate') AND cat_type='$funcType'"; $rhits = mysql_query($qhits); $rcount = mysql_num_rows($rhits); if ($rcount != 0) { while ($td = mysql_fetch_array($rhits)) { $group = $td['cat_group']; $chkDate = $td['date']; $res = $td['resolved']; $avg = $td['cat_aht']; // Today Calculations for Count & AVG AHT if ($group == 'cable' && $chkDate == $shiftstart) { $cab_avg_t = $cab_avg_t + $avg; $cab_t++; if ($res == 1) { $cab_resY_t++; } else { $cab_resN_t++; } } if ($group == 'common' && $chkDate == $shiftstart) { $com_avg_t = $com_avg_t + $avg; $com_t++; if ($res == 1) { $com_resY_t++; } else { $com_resN_t++; } } if ($group == 'internet' && $chkDate == $shiftstart) { $int_avg_t = $int_avg_t + $avg; $int_t++; if ($res == 1) { $int_resY_t++; } else { $int_resN_t++; } } if ($group == 'rhp' && $chkDate == $shiftstart) { $rhp_avg_t = $rhp_avg_t + $avg; $rhp_t++; if ($res == 1) { $rhp_resY_t++; } else { $rhp_resN_t++; } } if ($group == 'wireless' && $chkDate == $shiftstart) { $wir_avg_t = $wir_avg_t + $avg; $wir_t++; if ($res == 1) { $wir_resY_t++; } else { $wir_resN_t++; } } // Previous Day Calculations for Count & AVG AHT if ($group == 'cable' && $chkDate == $prevDate) { $cab_avg_p = $cab_avg_p + $avg; $cab_p++; //if ($res == 1) { $cab_resY_p++; } else { $cab_resN_p++; } } if ($group == 'common' && $chkDate == $prevDate) { $com_avg_p = $com_avg_p + $avg; $com_p++; //if ($res == 1) { $com_resY_p++; } else { $com_resN_p++; } } if ($group == 'internet' && $chkDate == $prevDate) { $int_avg_p = $int_avg_p + $avg; $int_p++; //if ($res == 1) { $int_resY_p++; } else { $int_resN_p++; } } if ($group == 'rhp' && $chkDate == $prevDate) { $rhp_avg_p = $rhp_avg_p + $avg; $rhp_p++; //if ($res == 1) { $rhp_resY_p++; } else { $rhp_resN_p++; } } if ($group == 'wireless' && $chkDate == $prevDate) { $wir_avg_p = $wir_avg_p + $avg; $wir_p++; //if ($res == 1) { $wir_resY_p++; } else { $wir_resN_p++; } } } } // Create Array of information for Totals and Averages for each Topic in $allTopics array. $item1 = array( 'tag' => $iTag, 'cab_t' => $cab_t, 'com_t' => $com_t, 'int_t' => $int_t, 'rhp_t' => $rhp_t, 'wir_t' => $wir_t, 'cab_p' => $cab_p, 'com_p' => $com_p, 'int_p' => $int_p, 'rhp_p' => $rhp_p, 'wir_p' => $wir_p, 'cab_avg_t' => $cab_avg_t, 'com_avg_t' => $com_avg_t, 'int_avg_t' => $int_avg_t, 'rhp_avg_t' => $rhp_avg_t, 'wir_avg_t' => $wir_avg_t, 'cab_avg_p' => $cab_avg_p, 'com_avg_p' => $com_avg_p, 'int_avg_p' => $int_avg_p, 'rhp_avg_p' => $rhp_avg_p, 'wir_avg_p' => $wir_avg_p, 'cab_resY_t' => $cab_resY_t, 'com_resY_t' => $com_resY_t, 'int_resY_t' => $int_resY_t, 'rhp_resY_t' => $rhp_resY_t, 'wir_resY_t' => $wir_resY_t, 'cab_resN_t' => $cab_resN_t, 'com_resN_t' => $com_resN_t, 'int_resN_t' => $int_resN_t, 'rhp_resN_t' => $rhp_resN_t, 'wir_resN_t' => $wir_resN_t // 'cab_resY_p' => $cab_resY_p, 'com_resY_p' => $com_resY_p, 'int_resY_p' => $int_resY_p, 'rhp_resY_p' => $rhp_resY_p, 'wir_resY_p' => $wir_resY_p, // 'cab_resN_p' => $cab_resN_p, 'com_resN_p' => $com_resN_p, 'int_resN_p' => $int_resN_p, 'rhp_resN_p' => $rhp_resN_p, 'wir_resN_p' => $wir_resN_p ); } function sec2hms ($sec, $padHours = false) { // holds formatted string $hms = ""; $hours = intval(intval($sec) / 3600); $hms .= ($padHours) ? str_pad($hours, 2, "0", STR_PAD_LEFT). 'h ' : $hours. 'h-'; // dividing the total seconds by 60 will give us // the number of minutes, but we're interested in // minutes past the hour: to get that, we need to // divide by 60 again and keep the remainder $minutes = intval(($sec / 60) % 60); // then add to $hms (with a leading 0 if needed) $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). 'm '; // seconds are simple - just divide the total // seconds by 60 and keep the remainder $seconds = intval($sec % 60); // add to $hms, again with a leading 0 if needed $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT); // done! return $hms . "s"; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Back Office - Tracker Report - <? echo ucwords($main); ?></title> <link href="../styles/text.css" rel="stylesheet" type="text/css"> <style type="text/css"> .tr.off { background: #ffffff; } .tr.on { background: #ffdbc7; } </style> <script language="javascript"> function launchUser() { var winW = 790; var winH = 620; var winl = (screen.width-winW)/2; var wint = (screen.height-winH)/2; if (winl < 0) winl = 0; if (wint < 0) wint = 0; window.open('../tracker/logged.php', 'activeUser', 'width='+winW+', height='+winH+', status=0, location=0, title=1, resizable=1, scrollbars=1, left='+winl+', top='+wint); } function show_sub(subID, state) { var subID; var state; var elText = "sub_id" + String(subID); var elLink = "expand_id" + String(subID); var linkID = "ah_" + String(subID); if (state == "close") { document.getElementById(linkID).href = "javascript:show_sub(\""+subID+"\",\"open\");"; document.getElementById(elText).style.display = "none"; } else { document.getElementById(linkID).href = "javascript:show_sub(\""+subID+"\", \"close\");"; document.getElementById(elText).style.display = "inline"; } } function hov(loc,cls){ if(loc.className) { loc.className=cls; } } function doRefresh() { window.location.reload(true); } function newSearch() { window.location.href = "track_report.php?sid=<? echo $_GET['sid']; ?>"; } function doColl() { var allTR = document.getElementsByTagName('tr'); for (d=0; d<allTR.length; d++) { var getTR = allTR[d]; var trID = getTR.id; var idStart = trID.substr(0,6); if (idStart == 'sub_id' && getTR.style.display != "none") { getTR.style.display = "none"; } } } function doExpand() { var allTR = document.getElementsByTagName('tr'); for (d=0; d<allTR.length; d++) { var getTR = allTR[d]; var trID = getTR.id; var idStart = trID.substr(0,6); if (idStart == 'sub_id' && getTR.style.display == "none") { getTR.style.display = "inline"; } } } </script> </head> <body> <form name='tracker' action='post'> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="main_text"> <tr> <td width="2%" align="left" valign="middle" bgcolor="#064363"> </td> <td width="91%" height="40" align="left" valign="middle" bgcolor="#064363"><span class="adh_bold_text stat_col_norm">Statistics Report for Back Office Tracker</span></td> <td width="5%" align="right" valign="middle" bgcolor="#064363"><input name="help" type="button" class="brbutt" onMouseOver="hov(this,'brhov')" onMouseOut="hov(this, 'brbutt')" onClick="" id="help" value="HELP"></td> <td width="2%" align="left" valign="middle" bgcolor="#064363"> </td> </tr> <tr> <td width="2%" align="left" valign="middle" bgcolor="#D3D3D3"> </td> <td height="20" align="left" valign="middle" bgcolor="#D3D3D3">Your results are displayed below for your convenience.</td> <td align="left" valign="middle" bgcolor="#D3D3D3"> </td> <td align="left" valign="middle" bgcolor="#D3D3D3"> </td> </tr> <tr> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top"> </td> <td align="left" valign="top"><input name="nsearch" type="button" class="brbutt" onMouseOver="hov(this,'brhov')" onMouseOut="hov(this, 'brbutt')" onClick="newSearch();" id="nsearch" value="New Search"> <input name="active" type="button" class="brbutt" onMouseOver="hov(this,'brhov')" onMouseOut="hov(this, 'brbutt')" onClick="launchUser();" id="active" value="Active Users"> <input name="active2" type="button" class="brbutt" onMouseOver="hov(this,'brhov')" onMouseOut="hov(this, 'brbutt')" onClick="doRefresh();" id="active2" value="Refresh"></td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> </tr> <tr> <td width="2%" align="left" valign="top"> </td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top"> </td> <td align="left" valign="top"> <table cellpadding='0' cellspacing='0' border='0' class='main_text'> <?php echo "<tr><td colspan='2'><font class='adh_bold_text'>".ucwords($main).", ".ucwords($funcType)." Results:</font></td></tr>"; echo "<tr><td colspan='2'> </td></tr>"; echo $out; ?> </table> </td> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> </tr> <tr> <td width="2%" align="left" valign="top"> </td> <td align="left" valign="top"></td> <td align="left" valign="top"></td> <td align="left" valign="top"> </td> </tr> </table> </form> </body> </html> <?php mysql_close($db); ?> Link to comment https://forums.phpfreaks.com/topic/103565-need-help-with-foreach-loops-can-this-be-done-easier/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.