Untitled
unknown
plain_text
2 years ago
4.9 kB
10
Indexable
<?php
require 'config.php';
$db = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
function kojatraka($sekunda)
{
if ($sekunda > 0 and $sekunda <= 25)
return '1';
if ($sekunda > 25 and $sekunda <= 45)
return '2';
if ($sekunda > 45 and $sekunda < 60)
return '3';
}
function vrtim($sekunda)
{
if ($sekunda <= 8)
return 'LIMIT 20 OFFSET 0';
if ($sekunda > 8 and $sekunda <= 16)
return 'LIMIT 20 OFFSET 20';
if ($sekunda > 16 and $sekunda <= 25)
return 'LIMIT 20 OFFSET 40';
if ($sekunda > 25 and $sekunda <= 32)
return 'LIMIT 20 OFFSET 0';
if ($sekunda > 32 and $sekunda <= 39)
return 'LIMIT 20 OFFSET 20';
if ($sekunda > 39 and $sekunda <= 45)
return 'LIMIT 20 OFFSET 40';
if ($sekunda > 45 and $sekunda <= 52)
return 'LIMIT 20 OFFSET 0';
if ($sekunda > 52 and $sekunda < 60)
return 'LIMIT 20 OFFSET 20';
}
function rankstart($sekunda)
{
if ($sekunda <= 8)
return '0';
if ($sekunda > 8 and $sekunda <= 16)
return '20';
if ($sekunda > 16 and $sekunda <= 25)
return '40';
if ($sekunda > 25 and $sekunda <= 32)
return '0';
if ($sekunda > 32 and $sekunda <= 39)
return '20';
if ($sekunda > 39 and $sekunda <= 45)
return '40';
if ($sekunda > 45 and $sekunda <= 52)
return '0';
if ($sekunda > 52 and $sekunda < 60)
return '20';
}
$wheredio = kojatraka(date('s'));
$limitiram = vrtim(date('s'));
$distartam = rankstart(date('s'));
if ($wheredio == '0') {
$query = "SELECT '' as RANK, res.ID, res.POINT as STAZA, res.VRIJEME as RACETIME, ";
$query = $query . " CONCAT(sw.NAME, ' ', sw.SURNAME, ' (', sw.COUNTRY, ')') as FULLNAME FROM results res LEFT JOIN swimmers sw ON ";
$query = $query . "res.ID = sw.ID WHERE ";
$query = $query . "res.TYPE <> 'c' AND res.IDACTIVE = '1' AND res.POINT = 0 ORDER BY res.PASSTIME DESC";
} else {
$query = "select CONCAT(@r := @r+1, '.') as RANK, rezultati.* from( ";
$query = $query . "select * from ( ";
$query = $query . "SELECT ID, FULLNAME, STAZA, ";
$query = $query . "timediff(CILJ, START) as RACETIME FROM ";
$query = $query . "(select res.*, CONCAT(sw.NAME, ' ', sw.SURNAME, ' (', sw.COUNTRY, '-', YEAR(sw.DOB), ')') as FULLNAME, ";
$query = $query . "max(case when res.POINT = 0 then res.PASSTIME end) AS START, ";
$query = $query . "max(case when res.TYPE <> 'p' and res.TYPE <> 'c' and res.POINT <> 0 then res.PASSTIME end) AS CILJ, ";
$query = $query . "max(case when res.TYPE <> 'p' and res.TYPE <> 'c' and res.POINT <> 0 then res.POINT end) AS STAZA ";
$query = $query . "FROM results res LEFT JOIN swimmers sw ON ";
$query = $query . "res.ID = sw.ID WHERE ";
$query = $query . "res.TYPE <> 'c' AND res.TYPE <> 'd' AND res.IDACTIVE = '1' group by res.ID ORDER BY res.PASSTIME DESC) as prva ";
$query = $query . ") as zadnja ";
$query = $query . ") as rezultati, (select @r:= " . $distartam . ") y WHERE STAZA = " . $wheredio . " order by ISNULL(RACETIME), RACETIME asc, ID ASC " . $limitiram . " ";
}
$result = mysql_query($query);
function klasa($point_value)
{
if ($point_value == '0')
return 'START';
if ($point_value == '1')
return '1500';
if ($point_value == '2')
return '3000';
if ($point_value == '3')
return '5000';
}
if ($wheredio == '0') {
print "
<thead>
<tr>
<th class='text-center'>ID</th>
<th class='text-left'>Full name</th>
<th class='text-center'>START TIME</th>
</tr>
</thead>
<tbody class='table-hover'>";
while ($row = mysql_fetch_array($result)) {
echo "<tr><td class='text-center'>" . $row['ID'] . "</td>";
echo "<td class='text-left'>" . $row['FULLNAME'] . "</td>";
echo "<td class='text-center'>" . $row['RACETIME'] . "</td></tr>";
}
mysql_close();
print " </tbody>";
} else {
$naslov = klasa(kojatraka(date('s')));
print "
<IMG class='displayed' src='" . $naslov . "1.jpg' alt='...'>
</div>
<table id='datatable' class='table-fill'>
<thead>
<tr>
<th class='text-center'>RANK</th>
<th class='text-center'>ID</th>
<th class='text-left'>NAME</th>
<th class='text-center'>TIME</th>
</tr>
</thead>
<tbody class='table-hover'>";
while ($row = mysql_fetch_array($result)) {
echo "<tr><td class='text-center'>" . $row['RANK'] . "</td>";
echo "<td class='text-center'>" . $row['ID'] . "</td>";
echo "<td class='text-left'>" . $row['FULLNAME'] . "</td>";
echo "<td class='text-center'>" . $row['RACETIME'] . "</td></tr>";
}
mysql_close();
print " </tbody>";
}
?>Editor is loading...