Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-23-2005, 10:41 AM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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;
    }
}

?>
Reply With Quote
  #2  
Old 06-23-2005, 05:46 PM
Guest190829
Guest
 
Posts: n/a
Default

Dont you have to make an new instance of the class? I can be completly wrong...
Reply With Quote
  #3  
Old 06-23-2005, 05:54 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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); 
Reply With Quote
  #4  
Old 06-23-2005, 06:24 PM
calorie calorie is offline
 
Join Date: May 2003
Posts: 2,804
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
    function DoStats($prs_stats, $updatetime)
    {
	global $DB_site;
        $this->updatetime = $updatetime;
	...
Reply With Quote
  #5  
Old 06-23-2005, 06:41 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #6  
Old 06-23-2005, 06:46 PM
calorie calorie is offline
 
Join Date: May 2003
Posts: 2,804
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Blush, no problem, glad I could help.
Reply With Quote
  #7  
Old 06-23-2005, 07:55 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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;
    } 
Reply With Quote
  #8  
Old 06-23-2005, 10:05 PM
calorie calorie is offline
 
Join Date: May 2003
Posts: 2,804
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

See the attached...
Attached Files
File Type: txt sabret00the.txt (4.1 KB, 5 views)
Reply With Quote
  #9  
Old 06-23-2005, 10:33 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #10  
Old 06-23-2005, 11:22 PM
calorie calorie is offline
 
Join Date: May 2003
Posts: 2,804
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:03 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07473 seconds
  • Memory Usage 2,350KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (8)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (1)postbit_attachment
  • (9)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete