vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   PHP Date() returning default value (https://vborg.vbsupport.ru/showthread.php?t=325079)

tinuz 05-15-2017 05:40 AM

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'


All times are GMT. The time now is 12:56 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.00920 seconds
  • Memory Usage 1,737KB
  • 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
  • (3)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (1)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete