Answer the question
In order to leave comments, you need to log in
MySQL: Fetching statistics by date range. How to implement?
Hello dear friends! There is a site with the statistics of the players of the hockey team. Their statistics are entered into the database: goals, passes, penalty minutes, etc. There was a need to divide the statistics into seasons, namely, to include dates from 11/1/2016 to 05/31/2017 in the sample.
Here is a code fragment of the functions.php page (CMS Joomla):
function stat_pl($sid, $tm, $fl) {
global $wpdb;
$query = "SELECT *, SUM(st.goal) AS bombordir, SUM(st.pas) AS asistent, SUM(st.goal+st.pas) AS gp ,SUM(st.wgoal) AS wins, SUM(st.bgoal) AS big, SUM(st.mgoal) AS small, SUM(st.pen) AS shtraf FROM "
. "stat AS st, game AS g, consist AS c, team AS tm, tourney AS tr, season AS sn WHERE "
. "st.gid = g.gid AND st.cid = c.cid AND c.tmid = tm.tmid AND tm.own = 1 AND tr.trid = sn.trid AND g.sid = sn.sid";
if($sid != 0) $query .= " AND sn.sid = ".$sid;
if($tm != 0) $query .= " AND tm.tmid = ".$tm;
$query .= " GROUP BY c.cid ORDER BY gp DESC LIMIT 10";
$res = $wpdb->get_results($query, ARRAY_A);
if($wpdb->num_rows > 0) {
?>
<div class="bheader">
<h3>Статистика игроков</h3>
</div>
<?php
// гол+пас
if($fl == 1) {
echo '<table class="stable"><tr><th>№</th><th align="left">Игрок</th><th width="7%">Г</th><th width="7%">П</th><th width="7%">О</th><th width="7%">ШМ</th><th width="7%">ГБ</th><th width="7%">ГМ</th></tr>';
$i = 0;
foreach ($res as $row) {
$ed = (($i+1)%2 == 0)? 'class="ed"' : '';
echo '<tr '.$ed.'><td align="center">'.$row['number'].'</td>';
$tmp = explode(' ', $row['cname']);
echo '<td>'.$tmp[0].' '.$tmp[1].'</td>';
echo '<td align="center">'.$row['bombordir'].'</td>';
echo '<td align="center">'.$row['asistent'].'</td>';
echo '<td align="center">'.$row['gp'].'</td>';
echo '<td align="center">'.$row['shtraf'].'</td>';
echo '<td align="center">'.$row['big'].'</td>';
echo '<td align="center">'.$row['small'].'</td></tr>';
$i++;
}
echo '</table><br><br>';
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question