blackhawx
Members-
Posts
10 -
Joined
-
Last visited
Profile Information
-
Gender
Not Telling
blackhawx's Achievements
Newbie (1/5)
0
Reputation
-
help on splitting and grouping array values
blackhawx replied to blackhawx's topic in PHP Coding Help
thanks -
help on splitting and grouping array values
blackhawx replied to blackhawx's topic in PHP Coding Help
That worked! I learned something new for me through this post, accessing a variable with get_template_vars, AFTER an array has appened all data. Never done that before but happy I did now! In addition to the script you posted I extended a step further. Not only can you call an associative array with get_template_vars but you can combine associative arrays to make a mega array like this... //here I am calling mtotalgames array and storing it into rtotalgames $rtotalgames = $smarty->get_template_vars('mtotalgames'); //this is to test out the value... /* print '<pre>'; print 'yes! we can call the mtotalgames array like this:'; print_r($rtotalgames); print '</pre>'; */ //you can also sort it sort($rtotalgames); //btherl's addition... $agg_total = array(); foreach ($rtotalgames as $n) { $agg_total[$n['team']] += $n['loss']; } $smarty->assign('agg_total', $agg_total); //now load another array that has matching keys called mwins... $rstats = $smarty->get_template_vars('mwins'); /* test it out... print '<pre>'; print 'yes! we can call the mwins array like this:'; print_r($rstats); print '</pre>'; */ sort($rstats); $agg_wins = array(); foreach ($rstats as $m) { $agg_wins[$m['team']] += $m['wins']; } $smarty->assign('agg_wins', $agg_wins); //Now do like voltron and combine them... $agg_grp = array_merge_recursive($agg_wins,$agg_total); //Now access parts of the the mega array with array_splice $array_div2 = array_slice($agg_grp, 0, 4); $array_div3 = array_slice($agg_grp, 4, 9); $array_naia = array_slice($agg_grp, 13); //And send the array portions back to smarty pages... $smarty->assign('agg_grp', $agg_grp); $smarty->assign('marray_div2',$array_div2); $smarty->assign('marray_div3',$array_div3); $smarty->assign('marray_naia',$array_naia); Thanks again btherl! -
help on splitting and grouping array values
blackhawx replied to blackhawx's topic in PHP Coding Help
thank you so much! I'll play with that tonight and let you know what i get tomorrow. bh -
help on splitting and grouping array values
blackhawx replied to blackhawx's topic in PHP Coding Help
Yes, every time I call a schedule tag, the udt code gets called each time and appends all the values into a large array called $game_info. Then I display $game_info back out into my smarty page with all the schedule values. I'm just trying to extend this UDT so that I can add up all the wins per $home team, as a separate array. It is challenging. But I do thank you very much for the help! I don't have any other code beyond what I have mentioned on his post... Let me say this...if there was a way in smarty that we can sum up the [wins] values where team name ="...", i think that would also be a possible solution... -
help on splitting and grouping array values
blackhawx replied to blackhawx's topic in PHP Coding Help
You mean how often I call the schedule tag on a page for a specific team? Like this... {schedule date="2010-11-13" time="7:05 p.m." location="Evansville" home="Oakland City" vs="Evansville" winner="University of Evansville" results="82-42"} {schedule date="2010-11-15" time="7:00 p.m." location="Oakland City" home="Oakland City" vs="OSU-Lima" winner="OSU-Lima" results="68-67 2OT"} {schedule date="2010-11-18" time="7:00 p.m." location="Logan" home="Oakland City" vs="Logan" winner="Logan" results="70-63"} {schedule date="2010-11-20" time="3:00 p.m." location="Oakland City" home="Oakland City" vs="OSU-Mansfield" winner="Oakland City" results="124-59"} {schedule date="2010-11-26" time="7:30 p.m." location="BYU-Hawaii" home="Oakland City" vs="BYU-Hawaii" winner="BYU-Hawaii" results="81-50"} {schedule date="2010-11-27" time="7:30 p.m." location="BYU-Hawaii" home="Oakland City" vs="BYU-Hawaii" winner="BYU-Hawaii" results="84-56"} {schedule date="2010-12-02" time="7:00 p.m." location="Oakland City" home="Oakland City" vs="Principia" winner= "Principia" results="86-42"} {schedule date="2010-12-04" time="3:00 p.m." location="Oakland City" home="Oakland City" vs="Concordia" winner= "Oakland City" results="74-42"} {schedule date="2010-12-11" time="3:00 p.m." location="Oakland City" home="Oakland City" vs="OU-Lancaster" winner= "Oakland City" results="81-56"} {schedule date="2010-12-12" time="3:30 p.m." location="Indiana State" home="Oakland City" vs="Indiana State" winner= "Oakland City" results="85-52"} {schedule date="2010-12-16" time="7:00 p.m." location="St. Louis" home="Oakland City" vs="St. Louis" winner="Oakland City" results="91-38"} {schedule date="2010-12-18" time="3:00 p.m." location="Oakland City" home="Oakland City" vs="Heritage Baptist" winner= "Oakland City" results="91-38"} -
help on splitting and grouping array values
blackhawx replied to blackhawx's topic in PHP Coding Help
this code is on my UDT (user defined tag)... for ($i=0; $i < count($params['date']); $i++) { $date= $params['date']; $time=$params['time']; $location= $params['location']; $home= $params['home']; $vs= $params['vs']; $winner= $params['winner']; $results= $params['results']; $gameinfo = array("date", "time","location","home","vs","winner","results"); $game_info = compact($gameinfo); if($home == $winner) { $record = array('team' => $winner, 'wins' => count($winner)); } } $smarty->append('mwins',$record); As you can see, I'm using the smarty append tag to merge my array because my {schedule ...} tag gets used multiple times on each page, per team. And on my smarty page I'm simplying testing how the array looks... <div style="display:block; clear:both;"> <pre> {$mwins|@print_r} </pre> </div> and I get this... 1 Array ( [0] => Array ( [team] => Oakland City [wins] => 1 ) [1] => Array ( [team] => Oakland City [wins] => 1 ) [2] => Array ( [team] => Oakland City [wins] => 1 ) [3] => Array ( [team] => Oakland City [wins] => 1 ) [4] => Array ( [team] => Oakland City [wins] => 1 ) [5] => Array ( [team] => Oakland City [wins] => 1 ) [6] => Array ( [team] => Oakland City [wins] => 1 ) [7] => Array ( [team] => Oakland City [wins] => 1 ) [8] => Array ( [team] => Oakland City [wins] => 1 ) [9] => Array ( [team] => Oakland City [wins] => 1 ) [10] => Array ( [team] => Oakland City [wins] => 1 ) [11] => Array ( [team] => Oakland City [wins] => 1 ) [12] => Array ( [team] => Oakland City [wins] => 1 ) [13] => Array ( [team] => Oakland City [wins] => 1 ) [14] => Array ( [team] => Oakland City [wins] => 1 ) [15] => Array ( [team] => Oakland City [wins] => 1 ) [16] => Array ( [team] => Oakland City [wins] => 1 ) [17] => Array ( [team] => Southern Indiana [wins] => 1 ) [18] => Array ( [team] => Southern Indiana [wins] => 1 ) [19] => Array ( [team] => Southern Indiana [wins] => 1 ) [20] => Array ( [team] => Southern Indiana [wins] => 1 ) [21] => Array ( [team] => Southern Indiana [wins] => 1 ) [22] => Array ( [team] => Southern Indiana [wins] => 1 ) [23] => Array ( [team] => Southern Indiana [wins] => 1 ) [24] => Array ( [team] => Southern Indiana [wins] => 1 ) [25] => Array ( [team] => Southern Indiana [wins] => 1 ) [26] => Array ( [team] => Southern Indiana [wins] => 1 ) [27] => Array ( [team] => Southern Indiana [wins] => 1 ) [28] => Array ( [team] => Southern Indiana [wins] => 1 ) [29] => Array ( [team] => Southern Indiana [wins] => 1 ) [30] => Array ( [team] => Southern Indiana [wins] => 1 ) [31] => Array ( [team] => Southern Indiana [wins] => 1 ) [32] => Array ( [team] => Southern Indiana [wins] => 1 ) [33] => Array ( [team] => Southern Indiana [wins] => 1 ) [34] => Array ( [team] => Southern Indiana [wins] => 1 ) [35] => Array ( [team] => Southern Indiana [wins] => 1 ) [36] => Array ( [team] => Southern Indiana [wins] => 1 ) [37] => Array ( [team] => Southern Indiana [wins] => 1 ) ) 1 If I can get my array to load the total win values per team, I'm a winner! haha -
help on splitting and grouping array values
blackhawx replied to blackhawx's topic in PHP Coding Help
as strange as it sounds...yes. I have it exactly in there. It looks like its totaling the winners per schedule tag used, which would lead to the 1 result per line. maybe we're in scope too deep? Thank you so much for the help!!! bh -
help on splitting and grouping array values
blackhawx replied to blackhawx's topic in PHP Coding Help
i get 1's listed all the way down with team names like this OaklandCity 1 OaklandCity 1 OaklandCity 1 OaklandCity 1 OaklandCity 1 OaklandCity 1 OaklandCity 1 OaklandCity 1 OaklandCity 1 OaklandCity 1 Southern Indiana University1 Southern Indiana University1 Southern Indiana University1 Southern Indiana University1 Southern Indiana University1 Southern Indiana University1 Southern Indiana University1 Southern Indiana University1 Southern Indiana University1 etc... -
help on splitting and grouping array values
blackhawx replied to blackhawx's topic in PHP Coding Help
thank you so much for the quick response - but no luck so far... -
I'm using smarty and php to collect parameters from a user defined tag in cmsms that looks like this... {schedule date="2010-11-13" time="7:05 p.m." location="Evansville" home="Oakland City" vs="Evansville" winner="University of Evansville" results="82-42"} {schedule date="2010-11-15" time="7:00 p.m." location="Oakland City" home="Oakland City" vs="OSU-Lima" winner="OSU-Lima" results="68-67 2OT"} etc... As you can see each {schedule tag above has the same home="" value. Thats because its schedule dates just for THAT team (i.e. Oakland City). So I may have 10 of these tags on the same page. But I also have other places where the schedule tag is used with a different $home name for another team. So basically I'm calling ALL these schedule tags into one for loop like this... for ($i=0; $i < count($params['date']); $i++) { $date= $params['date']; $time=$params['time']; $location= $params['location']; $home= $params['home']; $vs= $params['vs']; $winner= $params['winner']; $results= $params['results']; $gameinfo = array("date", "time","location","home","vs","winner","results"); $game_info = compact($gameinfo); } All I want to do is spit back out the total wins for each $home team. I am pulling out my hair out trying to get this thing to work but no luck yet, even though I see a little light. This is what I got so far... for ($i=0; $i < count($params['date']); $i++) { $date= $params['date']; $time=$params['time']; $location= $params['location']; $home= $params['home']; $vs= $params['vs']; $winner= $params['winner']; $results= $params['results']; $gameinfo = array("date", "time","location","home","vs","winner","results"); $game_info = compact($gameinfo); if($home == $winner) { $wins = array('team' => $winner, 'win' => count($winner)); } } $smarty->append('mwins',$wins); print '<pre>'; print_r($wins); print '</pre>'; and I get this... Array ( [0] => Array ( [team] => Oakland City [win] => 1 ) [1] => Array ( [team] => Oakland City [win] => 1 ) [2] => Array ( [team] => Oakland City [win] => 1 ) [3] => Array ( [team] => Oakland City [win] => 1 ) [4] => Array ( [team] => Oakland City [win] => 1 ) [5] => Array ( [team] => Oakland City [win] => 1 ) [6] => Array ( [team] => Oakland City [win] => 1 ) [7] => Array ( [team] => Oakland City [win] => 1 ) [8] => Array ( [team] => Oakland City [win] => 1 ) [9] => Array ( [team] => Oakland City [win] => 1 ) [10] => Array ( [team] => Oakland City [win] => 1 ) [11] => Array ( [team] => Oakland City [win] => 1 ) [12] => Array ( [team] => Oakland City [win] => 1 ) [13] => Array ( [team] => Oakland City [win] => 1 ) [14] => Array ( [team] => Oakland City [win] => 1 ) [15] => Array ( [team] => Oakland City [win] => 1 ) [16] => Array ( [team] => Oakland City [win] => 1 ) [17] => Array ( [team] => Southern Indiana [win] => 1 ) [18] => Array ( [team] => Southern Indiana [win] => 1 ) [19] => Array ( [team] => Southern Indiana [win] => 1 ) [20] => Array ( [team] => Southern Indiana [win] => 1 ) [21] => Array ( [team] => Southern Indiana [win] => 1 ) [22] => Array ( [team] => Southern Indiana [win] => 1 ) [23] => Array ( [team] => Southern Indiana [win] => 1 ) [24] => Array ( [team] => Southern Indiana [win] => 1 ) [25] => Array ( [team] => Southern Indiana [win] => 1 ) [26] => Array ( [team] => Southern Indiana [win] => 1 ) [27] => Array ( [team] => Southern Indiana [win] => 1 ) [28] => Array ( [team] => Southern Indiana [win] => 1 ) [29] => Array ( [team] => Southern Indiana [win] => 1 ) [30] => Array ( [team] => Southern Indiana [win] => 1 ) [31] => Array ( [team] => Southern Indiana [win] => 1 ) [32] => Array ( [team] => Southern Indiana [win] => 1 ) [33] => Array ( [team] => Southern Indiana [win] => 1 ) [34] => Array ( [team] => Southern Indiana [win] => 1 ) [35] => Array ( [team] => Southern Indiana [win] => 1 ) [36] => Array ( [team] => Southern Indiana [win] => 1 ) [37] => Array ( [team] => Southern Indiana [win] => 1 ) etc... I want to take all the [win] values for each [team] and add them up this way my final array looks like this... Array ( [0] => Array ( [team] => Oakland City [win] => 18 ) [1] => Array ( [team] => Southern Indiana [win] => 24 ) I know I'm so close but don't know how to solve the condition I need. Any suggestions would be great!!! bh