galvin Posted December 28, 2009 Share Posted December 28, 2009 I have a football pool website (using PHP and mySQL) where people pick 3 games each week and the standings are displayed on index.php (code for this page is below). Everything works fine, but there is a rule where the people with one of the TOP 7 regular season records get to advance to a "playoff pool." So I would like to add code that makes a "Playoff Line" automatically appear after the grouping of people with the 7th best record, so that people know that if they are ABOVE this line, they will make the playoffs. If they are BELOW it, they won't. The code below pulls info from the mySQL tables and churns out output consisting of a bunch tables (for each person and their record and their picks) and ordered by record (best record first obviously). So in basic form the output is like... Joe 43-5 Seth 42-6 Jim 42-6 Gary 41-7 etc, etc. So after the grouping for the people with 7th best record, it would display a DIV. Obviously, I have to somehow have the code counting each new, UNIQUE record until it gets to 7 and then output this DIV. I am just having trouble figuring that part out. Can anyone help me with the easiest way to do this type of thing? Ultimately, the basic output could be something like this... Joe 43-5 Seth 42-6 Jim 42-6 Gary 41-7 Dave 39-9 Kate 39-9 Jason 38-10 Matt 37-11 Doug 36-12 Casey 36-12 ***PLAYOFF LINE**** Mark 35-13 Terry 34-14 etc, etc. <?php require_once("includes/session.php"); require_once("includes/connection.php"); require_once("includes/functions.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>GSFL 2009 - League Standings</title> <link href="stylesheets/gsfl2009.css" media="all" rel="stylesheet" type="text/css" /> </head> <body> <div id="entirepage"> <?php require_once("includes/header.php"); ?> <?php function sortMultiArray($myRowArr, $assocOrNumericfieldIndex, $ascORdesc = 'asc'){ //Author: Dan //Refer by whichever type of index you know is available, (associative or numeric) //unset($myrow); //strange I had to unset this before using it. it was appending blank rows at the end for //some reason. actually doing the tradtional $myrow = array(); has the same effect $retArr = array(); $rowCount = count($myRowArr); if($rowCount){ $arrKeys = array_keys($myRowArr[0]); for ($x=0;$x<$rowCount;$x++) { $colarr[$x] = $myRowArr[$x][$assocOrNumericfieldIndex]; } //showArray($colarr); reset($arrKeys); //showArray($arrKeys); if(strtolower($ascORdesc) == 'asc'){ asort($colarr); // Use arsort=DESC or asort=ASC } elseif(strtolower($ascORdesc) == 'desc'){ arsort($colarr); // Use arsort=DESC or asort=ASC } $r = 0; for($sortedvar = reset($colarr); $sortedvar; $sortedvar= next($colarr)) { $rank = key($colarr); for ($y=0;$y<count($myRowArr[0]);$y++) { $retArr[$r][$arrKeys[$y]] = $myRowArr[$rank][$arrKeys[$y]]; } $r++; } } return($retArr); } echo "<span class=\"importantinfo\">Your picks will remain hidden until 12:59 PM on Sunday (NOTE: You can see your picks at anytime if you login)</span><br>"; echo "<span class='money'>Regular Season Prize Money: $750</span><br>"; echo "<span class='money'>Playoff Prize Money: $250</span>"; $outputStart = "<div id='standings'> <table class=\"standings\" cellpadding='1' cellspacing='1'> <tr> <th class='name'>Players (" . $rows . " total)</th> <th>Week 1</th> <th>Week 2</th> <th>Week 3</th> <th>Week 4</th> <th>Week 5</th> <th>Week 6</th> <th>Week 7</th> <th>Week 8</th> <th>Week 9</th> <th>Week 10</th> <th>Week 11</th> <th>Week 12</th> <th>Week 13</th> <th>Week 14</th> <th>Week 15</th> <th>Week 16</th> <th>Week 17</th> </tr>"; $user_set = mysql_query("SELECT * FROM users WHERE paid = 'yes'", $connection); if (!$user_set) { die("Database query failed: " . mysql_error()); } $userResArray = array(); $userCount = 0; while ($users = mysql_fetch_array($user_set)) { $userRow = "<tr><td id='name' class=\"name\">{$users["firstname"]}" . " " . "{$users["lastname"]}<br/>"; if (file_exists('images/userimages/user' . $users["userid"] . '.jpg')) { $userRow .= "<a href='#'><img src='images/userimages/user{$users['userid']}.jpg' width=30 /><span class='picture'><img src='images/userimages/user{$users['userid']}.jpg' /></span></a>"; } else { $userRow .= "<a href='#'><img src='images/userimages/noimage.jpg' width=30 /><span class='picture'><img src='images/userimages/noimage.jpg' /></span></a>"; } $userRow .= " <span class=\"record\">RecordPlaceHolder</span><br><span class=\"byesleft\">Byes Left: <span class=\"byesleftnumber\">${'byesleft_user_' . $users["userid"]}</span></span></td>"; /* $userRow .= '<td class="record">RecordPlaceHolder</td>'; */ $day = date("w"); $time = date("Hi"); $wins = 0; $losses = 0; for($x = 1; $x <= 17; $x++){ $userRow .= '<td>'; $sql = "SELECT teamname, result FROM teams, picks WHERE picks.userid = '{$users["userid"]}' AND picks.teamid = teams.teamid AND picks.week = '$x' "; $pick_set = mysql_query($sql, $connection); if (!$pick_set) { die("Database query failed: " . mysql_error()); } if(mysql_num_rows($pick_set)){ $userRow .= "<table class='inset' cellspacing='0' cellpadding='1'>\n"; while ($picks = mysql_fetch_array($pick_set)) { if ($picks['result'] == 'w') { $userRow .= "<tr><td class='pickwin' rowspan='1'>{$picks['teamname']}</td> </tr>\n"; $wins++; } elseif ($picks['result'] =='l') { $userRow .= "<tr><td class='pickloss' rowspan='1'>{$picks['teamname']}</td> </tr>\n"; $losses++; } elseif ((($picks['result'] == 'o') && ($day == 0) && ($time >= "1259")) || ($day == 1)) { $userRow .= "<tr><td class='pickopen' rowspan='1'>{$picks['teamname']}</td> </tr>\n"; } else { $userRow .= "<tr><td class='pickopenhidden' rowspan='1'> <span class=\"hide\">{$picks['teamname']}</span></td> </tr>\n"; } } $userRow .= "</table>\n"; } else { $userRow .= ' '; } $userRow .= '</td>'; } $userRow .= "</tr>\n"; $totalPicks = $wins + $losses; $successPercentage = 0; $totalWinLossText = ''; if($totalPicks > 0){ $successPercentage = $wins / $totalPicks; $totalWinLossText = " $wins-$losses"; if ($successPercentage == "1") { $rank = "name1"; } elseif (($successPercentage >= ".98") && ($successPercentage <= ".9999")) { $rank = "name2"; } elseif (($successPercentage >= ".96") && ($successPercentage <= ".9799")) { $rank = "name3"; } elseif (($successPercentage >= ".94") && ($successPercentage <= ".9599")) { $rank = "name4"; } elseif (($successPercentage >= ".92") && ($successPercentage <= ".9399")) { $rank = "name5"; } elseif (($successPercentage >= ".90") && ($successPercentage <= ".9199")) { $rank = "name6"; } elseif (($successPercentage >= ".88") && ($successPercentage <= ".8999")) { $rank = "name7"; } elseif (($successPercentage >= ".86") && ($successPercentage <= ".8799")) { $rank = "name8"; } elseif (($successPercentage >= ".84") && ($successPercentage <= ".8599")) { $rank = "name9"; } elseif (($successPercentage >= ".82") && ($successPercentage <= ".8399")) { $rank = "name10"; } elseif (($successPercentage >= ".80") && ($successPercentage <= ".8199")) { $rank = "name11"; } elseif (($successPercentage >= ".78") && ($successPercentage <= ".7999")) { $rank = "name12"; } elseif (($successPercentage >= ".76") && ($successPercentage <= ".7799")) { $rank = "name13"; } elseif (($successPercentage >= ".74") && ($successPercentage <= ".7599")) { $rank = "name14"; } elseif (($successPercentage >= ".72") && ($successPercentage <= ".7399")) { $rank = "name15"; } elseif (($successPercentage >= ".70") && ($successPercentage <= ".7199")) { $rank = "name16"; } elseif (($successPercentage >= ".68") && ($successPercentage <= ".6999")) { $rank = "name17"; } elseif (($successPercentage >= ".66") && ($successPercentage <= ".6799")) { $rank = "name18"; } elseif (($successPercentage >= ".64") && ($successPercentage <= ".6599")) { $rank = "name19"; } elseif (($successPercentage >= ".62") && ($successPercentage <= ".6399")) { $rank = "name20"; } elseif (($successPercentage >= ".60") && ($successPercentage <= ".6199")) { $rank = "name21"; } elseif (($successPercentage >= ".58") && ($successPercentage <= ".5999")) { $rank = "name22"; } elseif (($successPercentage >= ".56") && ($successPercentage <= ".5799")) { $rank = "name23"; } elseif (($successPercentage >= ".54") && ($successPercentage <= ".5599")) { $rank = "name24"; } elseif (($successPercentage >= ".52") && ($successPercentage <= ".5399")) { $rank = "name25"; } elseif (($successPercentage >= ".50") && ($successPercentage <= ".5199")) { $rank = "name26"; } elseif (($successPercentage >= ".48") && ($successPercentage <= ".4999")) { $rank = "name27"; } elseif (($successPercentage >= ".46") && ($successPercentage <= ".4799")) { $rank = "name28"; } elseif (($successPercentage >= ".44") && ($successPercentage <= ".4599")) { $rank = "name29"; } elseif (($successPercentage >= ".42") && ($successPercentage <= ".4399")) { $rank = "name30"; } elseif (($successPercentage >= ".40") && ($successPercentage <= ".4199")) { $rank = "name31"; } elseif (($successPercentage >= ".38") && ($successPercentage <= ".3999")) { $rank = "name32"; } elseif (($successPercentage >= ".36") && ($successPercentage <= ".3799")) { $rank = "name33"; } elseif (($successPercentage >= ".34") && ($successPercentage <= ".3599")) { $rank = "name34"; } elseif (($successPercentage >= ".32") && ($successPercentage <= ".3399")) { $rank = "name35"; } elseif (($successPercentage >= ".30") && ($successPercentage <= ".3199")) { $rank = "name36"; } else { $rank = "name"; } } $find = array('RecordPlaceHolder', 'name'); $replace = array($totalWinLossText, $rank); $userResArray[$userCount]['row'] = str_replace($find, $replace, $userRow); $userResArray[$userCount]['percentage'] = $successPercentage; $userCount++; } $userResArraySorted = sortMultiArray($userResArray, 'percentage', 'desc'); $outputEnd = "</table>\n"; $outputEnd .= "</div>\n"; //Write the data table now echo $outputStart; for($x = 0; $x < count($userResArraySorted); $x++){ echo $userResArraySorted[$x]['row']; } echo $outputEnd; ?> </div> </body> </html> <?php require_once("includes/footer.php"); ?> Link to comment https://forums.phpfreaks.com/topic/186498-making-a-div-appear-in-one-certain-area-of-output/ Share on other sites More sharing options...
Catfish Posted December 28, 2009 Share Posted December 28, 2009 i didn't look through your code but it sounds like you would need to: use a for() loop inside that loop: increment a counter value check the counter to see if it is 7 then output a div, else do nothing. Link to comment https://forums.phpfreaks.com/topic/186498-making-a-div-appear-in-one-certain-area-of-output/#findComment-985114 Share on other sites More sharing options...
galvin Posted December 29, 2009 Author Share Posted December 29, 2009 Ok, I think I know what to do once I have an array of unique WIN totals. But I'm still unsure how to get that array. Can anyone offer any help on how to loop through a bunch of win totals and put ONLY THE UNIQUE ONES into an array? Like if win totals are... 43 42 42 42 41 41 40 39 39 39 I would want the array to just have each one once, i.e... 43 42 41 40 39 Link to comment https://forums.phpfreaks.com/topic/186498-making-a-div-appear-in-one-certain-area-of-output/#findComment-985253 Share on other sites More sharing options...
Catfish Posted January 2, 2010 Share Posted January 2, 2010 array_search — Searches the array for a given value and returns the corresponding key if successful http://au.php.net/manual/en/function.array-search.php See also: http://au.php.net/manual/en/ref.array.php Example of use: <?php $arrayWithUniqueValues = array(); // array to store unique values only foreach ($arrayWithSimilarValues as $key => $value) // array with values which may reoccur { if (!array_search($value, $arrayWithUniqueValues)) // if $value is NOT found in $arrayWithUniqueValues (searching values only) $arrayWithUniqueValues[] = $value; // place $value in $arrayWithUniqueValues (else do nothing) } print_r($arrayWithSimilarValues); // debug purposes print_r($arrayWithUniqueValues); // debug purposes ?> Sorry for delaying, I was on one of Australia's most isolated islands for a few days. Link to comment https://forums.phpfreaks.com/topic/186498-making-a-div-appear-in-one-certain-area-of-output/#findComment-987094 Share on other sites More sharing options...
galvin Posted January 2, 2010 Author Share Posted January 2, 2010 Awesome thanks!!! Link to comment https://forums.phpfreaks.com/topic/186498-making-a-div-appear-in-one-certain-area-of-output/#findComment-987340 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.