Trouble with stats...

Started by Hyperion (noobKID), December 19, 2013, 01:57:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Hyperion (noobKID)

i fixed the problem.
In case someone wishes the code for my fix, here it is:

Code (php) Select

// TORRENTS - NORMAL ROW
$torrents = ($row['torrents'] == 0) ? 0 : $row['torrents'];

// TORRENTS - DAY
$torrentstoday = ($row['torrentstoday'] == 0) ? 0 : $row['torrentstoday'];
$day_fixed = ($torrentstoday == 0) ? 0 : number_format(($torrentstoday/$torrents)*100);
$day = ($day_fixed == 0) ? 0 : $day_fixed;

// TORRENTS - WEEK
$torrentsweek = ($row['torrentsweek'] == 0) ? 0 : $row['torrentsweek'];
$week_fixed = ($torrentsweek == 0) ? 0 : number_format(($torrentsweek/$torrents)*100);
$week = ($week_fixed == 0) ? 0 : $week_fixed;

// TORRENTS - MONTH
$torrentsmonth = ($row['torrentsmonth'] == 0) ? 0 : $row['torrentsmonth'];
$month_fixed = ($torrentsmonth == 0) ? 0 : number_format(($torrentsmonth/$torrents)*100);
$month = ($month_fixed == 0) ? 0 : $month_fixed;

// TORRENTS - LEECHED / MONTH
$torrentslmonth = ($row['torrentslmonth'] == 0) ? 0 : $row['torrentslmonth'];
$lmonth_fixed = ($torrentslmonth == 0) ? 0 : number_format(($torrentslmonth/$torrents)*100);
$lmonth = ($lmonth_fixed == 0) ? 0 : $lmonth_fixed;


I dont know if the fix already has been applied so far to other source (v2, v3, etc...)
But i think this should work.

I used IF/ELSE statements to stop the dividing with 0 to get the damn errors away.. (about time) x)...

Thanks for the support/ideas anyways! :)

autotron

try

$stats = mysql_fetch_assoc(sql_query("SELECT *, seeders + leechers AS peers, seeders / leechers AS ratio, unconnectables / (seeders + leechers) AS ratiounconn FROM stats WHERE id = '1' LIMIT 1"));

Hyperion (noobKID)

Ok, so i'm trying to fix my stats.php file.

Im getting a "Divizion by zero" error. I do know what it means, but how can i fix that part Oo.

This is my code so far:

Code (php) Select

//== 09 stats

$cache_stats = "./cache/stats.txt";
$cache_stats_life = 2 * 60; // 2min

if (file_exists($cache_stats) && is_array(unserialize(file_get_contents($cache_stats))) && (time() - filemtime($cache_stats)) < $cache_stats_life)
$row = unserialize(@file_get_contents($cache_stats));
else
{
$stats = sql_query("SELECT *, seeders + leechers AS peers, seeders / leechers AS ratio, unconnectables / (seeders + leechers) AS ratiounconn FROM stats WHERE id = '1' LIMIT 1") or sqlerr(__FILE__, __LINE__);
$row = mysql_fetch_assoc($stats);
$handle = fopen($cache_stats, "w+");
fwrite($handle, serialize($row));
fclose($handle);
}

// ROWS
// -----------------------
$seeders = number_format($row['seeders']);
$leechers = number_format($row['leechers']);
$registered = number_format($row['regusers']);
$unverified = number_format($row['unconusers']);
$torrents = ($row['torrents']);
$torrentstoday = ($row['torrentstoday']);
$day = number_format(($torrentstoday/$torrents)*100);
$torrentsweek = ($row['torrentsweek']);
$week = number_format(($torrentsweek/$torrents)*100);
$torrentsmonth = ($row['torrentsmonth']);
$month = number_format(($torrentsmonth/$torrents)*100);
$torrentslmonth = ($row['torrentslmonth']);
$lmonth = number_format(($torrentslmonth/$torrents)*100);
$ratiounconn = $row['ratiounconn'];
$unconnectables = $row['unconnectables'];
$ratio = round(($row['ratio'] * 100));
$peers = number_format($row['peers']);
$numactive = number_format($row['numactive']);
$donors = number_format($row['donors']);
$forumposts = number_format($row['forumposts']);
$forumtopics = number_format($row['forumtopics']);

$result = sql_query("SELECT SUM(downloaded) AS totaldl, SUM(uploaded) AS totalul FROM users") or sqlerr(__FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
$totaldownloaded = mksize($row["totaldl"]);
$totaluploaded = mksize($row["totalul"]);
$totaltraffic = mksize($row["totalul"]+$row["totaldl"]);

$HTMLOUT .="
<div class='stats container'>
<div>
<h2 class='stats'>{$lang['index_stats_title']}</h2>
</div>
<br />

<table width='100%' border='1' cellspacing='0' cellpadding='10'>
<tr>
<td align='center'>
<table border='1' cellspacing='0' cellpadding='5'>
<tr>
<td class='rowhead'>{$lang['index_stats_regged']}</td><td align='right'>{$registered}/{$TBDEV['maxusers']}</td>
<td class='rowhead'>{$lang['index_stats_online']}</td><td align='right'>{$numactive}</td>
<td class='rowhead'>{$lang['index_stats_uncon']}</td><td align='right'>{$unverified}</td>
</tr>

<tr>
<td class='rowhead'>{$lang['index_stats_donor']}</td><td align='right'>{$donors}</td>
<td class='rowhead'>{$lang['index_stats_topics']}</td><td align='right'>{$forumtopics}</td>
<td class='rowhead'>{$lang['index_stats_posts']}</td><td align='right'>{$forumposts}</td>
</tr>

<tr>
<td colspan='4'> </td>
</tr>

<tr>
<td class='rowhead'>{$lang['index_stats_torrents']}</td><td align='right'>{$torrents}</td>
<td class='rowhead'>{$lang['index_stats_newtor']}</td><td align='right'>{$torrentstoday} ({$day} %)</td>
<td class='rowhead'>{$lang['index_stats_week']}</td><td align='right'>{$torrentsweek} ({$week} %)</td>
</tr>

<tr>
<td class='rowhead'>{$lang['index_stats_month']}</td><td align='right'>{$torrentsmonth} ({$month} %)</td>
<td class='rowhead'>{$lang['index_stats_lmonth']}</td><td align='right'>{$torrentslmonth} ({$lmonth} %)</td>
<td class='rowhead'>{$lang['index_stats_traffic']}</td><td align='right'>{$totaltraffic}</td>
</tr>

<tr>
<td colspan='4'> </td>
</tr>

<tr>
<td class='rowhead'>{$lang['index_stats_peers']}</td><td align='right'>{$peers}</td>
<td class='rowhead'>{$lang['index_stats_seeders']}</td><td align='right'>{$seeders}</td>
<td class='rowhead'>{$lang['index_stats_leechers']}</td><td align='right'>{$leechers}</td>
</tr>

<tr>
<td class='rowhead'>{$lang['index_stats_unconpeer']}</td><td align='right'>{$unconnectables}</td>
<td class='rowhead' align='right'><b>{$lang['index_stats_unconratio']}</b></td><td align='right'><b>".round($ratiounconn * 100)."</b></td>
<td class='rowhead'>{$lang['index_stats_slratio']}</td><td align='right'>{$ratio}</td>
</tr>
</table>
</td>
</tr>
</table>
</div><br />";


Any ideas?
I did try with something like this in the top:

Code (php) Select

$torrentstoday = ($row['torrentstoday'] == 0) ? 0 : $row['torrentstoday'];


Instead of this:

Code (php) Select

$torrentstoday = ($row['torrentstoday']);


But i guess that dosen't change the part where it shows error :/...

Ideas and tips/codes would be MUCH! Apreciated! :D

-noobKID :D