Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 05-15-2017, 05:40 AM
tinuz tinuz is offline
 
Join Date: Apr 2016
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP Date() returning default value

Hey guys. I'm currently working on a new mod for vBulletin 4.x

In short it's a new panel that allows teammembers to monitor for new posts on the forum through Ajax, like the mod over here: https://vborg.vbsupport.ru/showthread.php?t=125947, but instead of working like a RSS feed, it only shows posts that haven't been checked by a teammember. Once a teammember opened the post or new thread, it disappears from the list.

Anyway, right now I'm working on a small part that keeps track of how many posts were checked by each teammember every single day. For that I'm editing the file:

Code:
includes/functions_bigthree.php
After the query inside the if-statement on line 168:

PHP Code:
if ($vbulletin->options['threadmarking'] AND $userid
I've written the following:

PHP Code:
/* Custom post read count mod */
$modP_teamIDs = array(1,2,3,4,5,6,7,8,9);
$modP_today date("Y-m-d");

if(
array_search($userid$modP_teamIDs) !== false){
    
$modP_getToday $db->query_read("
        SELECT posts
        FROM " 
.TABLE_PREFIX ."postsreadcount
        WHERE userid = 
$userid
            AND mydate = 
$modP_today
    "
);

    
$modP_getToday_count $db->num_rows($modP_getToday);

    if(
$modP_getToday_count 0){
        while(
$modP_getToday_fetch $db->fetch_array($modP_getToday)){
            
$modP_posts $modP_getToday_fetch['posts'];
        }
        
$modP_posts++;

        
$db->query_write("
            UPDATE " 
TABLE_PREFIX "postsreadcount
            SET posts = 
$modP_posts
            WHERE userid = 
$userid
                AND mydate = 
$modP_today
        "
);
    } else {
        
$modP_posts 1;

        
$db->query_write("
            INSERT INTO " 
TABLE_PREFIX "postsreadcount
                (userid, mydate, posts)
            VALUES
                (
$userid$modP_today$modP_posts)
        "
);
    }
}
/* End custom post count mod */ 
The code is working perfectly fine, but

PHP Code:
$modP_today date("Y-m-d"); 
is returning me 0000-00-00 instead of the current date as I would expect. I know I could use the constant TIMENOW defined in vBulletin, but that one returns a UNIX timestamp, instead of a normal date.

So could anyone tell me why this is happening? Could be a local scope problem?

--------------- Added [DATE]1494835639[/DATE] at [TIME]1494835639[/TIME] ---------------

I've fixed the issue by using CURDATE() inside my queries instead of relying on PHP to do it. Still, if anyone could tell me why it didn't work, that would be perfect

--------------- Added [DATE]1494855999[/DATE] at [TIME]1494855999[/TIME] ---------------

It turns out the variable was returning the correct date as expected. I should've wrapped the variable inside quotes in the queries: AND mydate = '$modP_today'
Reply With Quote
Reply

Thread Tools
Display Modes

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 07:48 AM.


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.04511 seconds
  • Memory Usage 2,167KB
  • Queries Executed 11 (?)
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
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete