Created
October 31, 2019 23:17
-
-
Save Kcko/5830b9ae008b3488ad1862d0a86fc6ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$hodnoty = array( | |
"baku" => array(3, 4, 7), | |
"kcko" => array(2, 5, 7), | |
"guest" => array(1, 2, 2) | |
); | |
$data = array(); | |
foreach ($hodnoty as $pole => $k) | |
{ | |
$counter = 0; | |
foreach ($k as $i) | |
{ | |
$counter++; | |
//echo "$pole - $i [$counter] <br />"; | |
$data[$pole]["komentar" . $counter] = $i; | |
if ($counter ==3 ) | |
{ | |
$data[$pole]["komentarCelkem"] = array_sum($hodnoty[$pole]); | |
} | |
} | |
} | |
print_r($data); | |
$dataSort = valuesToColumns($data); | |
array_multisort( | |
$dataSort["komentarCelkem"], SORT_NUMERIC, SORT_DESC, | |
$dataSort["komentar1"], SORT_NUMERIC, SORT_DESC, | |
$dataSort["komentar2"], SORT_NUMERIC, SORT_DESC, | |
$dataSort["komentar3"], SORT_NUMERIC, SORT_DESC | |
); | |
print_r($dataSort); | |
$tab = "<table border=1>"; | |
$tab .= "<tr><th>Nick</th> <th>Komentář Celkem</th> <th>Komentář 1</th> <th>Komentář 2</th> <th>Komentář 3</th> </tr>"; | |
foreach ($dataSort["komentar1"] as $K => $V) | |
{ | |
$tab .= "<tr>"; | |
$tab .= "<td>$K</td>"; | |
$tab .= "<td>". $data[$K]["komentarCelkem"] ."</td>"; | |
$tab .= "<td>". $data[$K]["komentar1"] ."</td>"; | |
$tab .= "<td>". $data[$K]["komentar2"] ."</td>"; | |
$tab .= "<td>". $data[$K]["komentar3"] ."</td>"; | |
$tab .= "</tr>"; | |
} | |
$tab .= "</table>"; | |
echo $tab; | |
function valuesToColumns($array_to_sort) | |
{ | |
$sort_arr = array(); | |
foreach($array_to_sort AS $uniqid => $row) | |
{ | |
foreach($row AS $key=>$value){ | |
$sort_arr[$key][$uniqid] = $value; | |
} | |
} | |
return $sort_arr; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
mysql_connect("localhost", "root", ""); | |
mysql_select_db("***"); | |
$q = " SELECT * FROM vysledky WHERE id_souteze = 1 AND schvaleno = 2 "; | |
$mq = mysql_query($q); | |
$tym = array(); | |
$tymyID = array(38, 33, 35, 37, 34, 36, 39); | |
$polozky = array("zapasy", "v", "r", "p", "gf", "ga"); | |
foreach ($polozky as $A) | |
{ | |
foreach ($tymyID as $B) | |
{ | |
$tym[$A][$B] = 0; | |
} | |
} | |
while ($r = mysql_fetch_object($mq)) | |
{ | |
$tym['ID'][$r->d_tym] = $r->d_tym; | |
// vyhra domaciho | |
if ($r->d_goly > $r->h_goly) | |
{ | |
$tym['zapasy'][$r->d_tym]++; | |
$tym['v'][$r->d_tym]++; | |
$tym['gf'][$r->d_tym] += $r->d_goly; | |
$tym['ga'][$r->d_tym] += $r->h_goly; | |
} | |
// remiza domaciho | |
elseif ($r->d_goly == $r->h_goly) | |
{ | |
$tym['zapasy'][$r->d_tym]++; | |
$tym['r'][$r->d_tym]++; | |
$tym['gf'][$r->d_tym] += $r->d_goly; | |
$tym['ga'][$r->d_tym] += $r->h_goly; | |
} | |
// prohra domaciho | |
elseif ($r->d_goly < $r->h_goly) | |
{ | |
$tym['zapasy'][$r->d_tym]++; | |
$tym['p'][$r->d_tym]++; | |
$tym['gf'][$r->d_tym] += $r->d_goly; | |
$tym['ga'][$r->d_tym] += $r->h_goly; | |
} | |
} | |
$q = " SELECT * FROM vysledky WHERE id_souteze = 1 AND schvaleno = 2 "; | |
$mq = mysql_query($q); | |
while ($r = mysql_fetch_object($mq)) | |
{ | |
$tym['ID'][$r->h_tym] = $r->h_tym; | |
// vyhra hosta | |
if ($r->d_goly < $r->h_goly) | |
{ | |
$tym['zapasy'][$r->h_tym]++; | |
$tym['v'][$r->h_tym]++; | |
$tym['gf'][$r->h_tym] += $r->h_goly; | |
$tym['ga'][$r->h_tym] += $r->d_goly; | |
} | |
// remiza hosta | |
elseif ($r->d_goly == $r->h_goly) | |
{ | |
$tym['zapasy'][$r->h_tym]++; | |
$tym['r'][$r->h_tym]++; | |
$tym['gf'][$r->h_tym] += $r->h_goly; | |
$tym['ga'][$r->h_tym] += $r->d_goly; | |
} | |
// prohra hosta | |
elseif ($r->d_goly > $r->h_goly) | |
{ | |
$tym['zapasy'][$r->h_tym]++; | |
$tym['p'][$r->h_tym]++; | |
$tym['gf'][$r->h_tym] += $r->h_goly; | |
$tym['ga'][$r->h_tym] += $r->d_goly; | |
} | |
} | |
print_r($tym); | |
ksort($tym); | |
array_multisort ($tym[v], SORT_DESC, SORT_NUMERIC); | |
echo "<table border=1 style='width: 400px;'>"; | |
echo "<tr>"; | |
echo "<th>ID</th>"; | |
echo "<th>Z</th>"; | |
echo "<th>V</th>"; | |
echo "<th>R</th>"; | |
echo "<th>P</th>"; | |
echo "<th>GF</th>"; | |
echo "<th>GA</th>"; | |
echo "</tr>"; | |
foreach ($tym['zapasy'] as $key => $value ) | |
{ | |
echo "<tr>"; | |
echo "<td>".$tym['ID'][$key]."</td>"; | |
echo "<td>".$tym['zapasy'][$key]."</td>"; | |
echo "<td>".$tym['v'][$key]."</td>"; | |
echo "<td>".$tym['r'][$key]."</td>"; | |
echo "<td>".$tym['p'][$key]."</td>"; | |
echo "<td>".$tym['gf'][$key]."</td>"; | |
echo "<td>".$tym['ga'][$key]."</td>"; | |
echo "</tr>"; | |
} | |
echo "</table>"; | |
/* | |
echo "<pre>"; | |
print_r($tym); | |
echo "</pre>"; | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment