vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   class making page blank (https://vborg.vbsupport.ru/showthread.php?t=90894)

sabret00the 06-23-2005 09:41 AM

class making page blank
 
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'] == OR ($prs_stats['lastupdate'] + ($this->updatetime 60)) < TIMENOW)
        {
            
$starttime mktime(000date('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;
    }
}

?>


Guest190829 06-23-2005 04:46 PM

Dont you have to make an new instance of the class? I can be completly wrong...

sabret00the 06-23-2005 04:54 PM

i don't think so, i.e. it's called in my page via
PHP Code:

$makestats DoStats($prs_stats15);
$prs_stats $makestats->StatsFormat($make_stats); 


calorie 06-23-2005 05:24 PM

Code:


    function DoStats($prs_stats, $updatetime)
    {
        global $DB_site;
        $this->updatetime = $updatetime;
        ...


sabret00the 06-23-2005 05:41 PM

calorie, i am so so so so so grateful to you, you dont' know how much, this has been bothering me since yesterday, thank you very much for helping my first class come to life, unfortunately i never finished my database schema in order to test it properly, but it is throwing up the correct errors, thank you again :)

calorie 06-23-2005 05:46 PM

Blush, no problem, glad I could help. :)

sabret00the 06-23-2005 06:55 PM

Ok now i've finished the database scheme (i guess this is what you get from coding from the front-end)

i'm getting this when i do a print_r on the $makestats
PHP Code:

$makestats = new DoStats($prs_stats15);
$prs_stats $makestats->StatsFormat($makestats);

print_r($makestats); 

it's giving me this
PHP Code:

DoStats Object ( [DoStats] => Array ( [totalpieces] => [totalreviews] => [avgrate] => [toprated] => [toprated_pieceid] => [topreviewed] => [topreviewed_pieceid] => [topviewed] => [topviewed_pieceid] => [topposter] => [topposterid] => [topreviewer] => [topreviewerid] => [lastupdate] => 1119559839 ) [GetStats] => Array ( [0] => Array ( [totalpieces] => [totalreviews] => [avgrate] => [toprated] => [toprated_pieceid] => [topreviewed] => [topreviewed_pieceid] => [topviewed] => [topviewed_pieceid] => [topposter] => [topposterid] => [topreviewer] => [topreviewerid] => [lastupdate] => 1119559839 ) [1] => Array ( [0] => Array ( [totalpieces] => [totalreviews] => [avgrate] => [toprated] => [toprated_pieceid] => [topreviewed] => [topreviewed_pieceid] => [topviewed] => [topviewed_pieceid] => [topposter] => [topposterid] => [topreviewer] => [topreviewerid] => [lastupdate] => 1119559839 ) ) ) ) 

it's got 4 arrays in the makestats instead of just overwriting it and giving me the last one, how would i remedy this?

the bit in question (making the $makestats->GetStats[$var]) is
PHP Code:

    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;
    } 


calorie 06-23-2005 09:05 PM

1 Attachment(s)
See the attached...

sabret00the 06-23-2005 09:33 PM

thanks though i managed to fix it by changing
PHP Code:

        return $this->GetStats

into
PHP Code:

        return $this->GetStats['0']['1']; 

but i reckon yours is the cleaner code.

though i have one more problem, sorry about this.

debugging the code i have
PHP Code:

$prs_stats1 unserialize($datastore['prs_stats']);
echo 
$prs_stats1 "<--";
print_r($prs_stats1);
$makestats = new DoStats($prs_stats115);
$prs_stats2 $makestats->StatsFormat($makestats); 

the problem is though, that $prs_stats1 is returning nothing, while $datastore is giving the correct array, it's like $prs_stats1 isn't unseralizing.

the reason $prs_stats1 is go relevant is because of the conditional in the first method of the class that saves me 8 queries

calorie 06-23-2005 10:22 PM

Do a print_r on $datastore and see if there is a value for the prs_stats key.


All times are GMT. The time now is 08:53 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01774 seconds
  • Memory Usage 1,814KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (8)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete