this is my first ever class so i'm not sure why it's going wrong or where but hey it's the only way i'll learn right?
could someone tell me where i'm going wrong, it's based off of Boofo's stats serialize hack
PHP Code:
<?php
class DoStats
{
var $prs_stats = array();
var $updatetime;
// var TIMENOW;
function DoStats($prs_stats, $updatetime)
{
$this->updatetime = $updatetime;
//$this->prs_stats = $prs_stats;
if (!$this->prs_stats['lastupdate'])
{
$this->prs_stats['lastupdate'] = 0;
}
if ($prs_stats['lastupdate'] == 0 OR ($prs_stats['lastupdate'] + ($this->updatetime * 60)) < TIMENOW)
{
$starttime = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
// Total Pieces
$stats_totalpieces = @$DB_site->query_first("
SELECT COUNT(*) AS count
FROM prs_pieces
");
// Total Reviews
$stats_totalreviews = @$DB_site->query_first("
SELECT COUNT(*) AS count
FROM prs_reviews
");
// Average Rating
$stats_avgrate = @$DB_site->query_first("
SELECT AVG(rating) AS avg
FROM prs_rating
");
// Top Rated Piece
$stats_toprated = @$DB_site->query_first("
SELECT COUNT(prs_ratings.rating) AS count, *
FROM prs_ratings
LEFT JOIN prs_pieces ON (prs_pieces.pieceid = prs_rating.pieceid)
ORDER BY count
DESC LIMIT 1
");
// might need to change this into a quick query of select from piece 'review_count' order by review count
// Top Reviewed
$stats_topreviewed = @$DB_site->query_first("
SELECT COUNT(prs_reviews.pagetext) AS count, *
FROM prs_reviews
LEFT JOIN prs_pieces ON (prs_pieces.pieceid = prs_reviews.pieceid)
ORDER BY count
DESC LIMIT 1
");
// Top Viewed
$stats_topviewed = @$DB_site->query_first("
SELECT *
FROM prs_views
ORDER BY views
DESC LIMIT 1
");
// Top Poster
$stats_topposter = @$DB_site->query_first("
SELECT *
FROM prs_user
ORDER BY pieces DESC
LIMIT 1
");
// Top Reviewer
$stats_topreviewer = @$DB_site->query_first("
SELECT *
FROM prs_user
ORDER BY reviews DESC
LIMIT 1
");
$prs_stats['totalpieces'] = intval($stats_totalpieces[count]);
$prs_stats['totalreviews'] = intval($stats_totalreviews[count]);
$prs_stats['avgrate'] = intval(ceil($stats_avgrate[avg]));
$prs_stats['toprated'] = $stats_toprated[title];
$prs_stats['toprated_pieceid'] = intval($stats_toprated[pieceid]);
$prs_stats['topreviewed'] = $stats_topreviewed[title];
$prs_stats['topreviewed_pieceid'] = intval($stats_topreviewed[pieceid]);
$prs_stats['topviewed'] = $stats_topviewed[title];
$prs_stats['topviewed_pieceid'] = intval($stats_topviewed[pieceid]);
$prs_stats['topposter'] = $stats_topposter[username];
$prs_stats['topposterid'] = intval($stats_topposter[userid]);
$prs_stats['topreviewer'] = $stats_topreviewer[username];
$prs_stats['topreviewerid'] = intval($stats_topreviewer[userid]);
$prs_stats['lastupdate'] = intval(TIMENOW);
$DB_site->query ("
REPLACE INTO " . TABLE_PREFIX . "datastore(title, data)
VALUES ('prs_stats', '" . addslashes(serialize($prs_stats)) . "')
");
$this->DoStats = $prs_stats;
// should return the array prs_stats
}
else
{
$this->DoStats = $prs_stats;
//return array prs_stats;
}
return $this->DoStats;
}
function StatsFormat($prs_stats)
{
foreach($prs_stats AS $key => $value)
{
if (is_numeric($value))
{
$this->GetStats[] = vb_number_format($value);
}
else
{
$this->GetStats[] = $value
}
}
return $this->GetStats;
}
}
?>