vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   showthread_query hook sql (https://vborg.vbsupport.ru/showthread.php?t=98956)

Nullifi3d 10-21-2005 03:16 PM

showthread_query hook sql
 
PHP Code:

$banner $db->query_first("SELECT userid, title, ext, width, height FROM " TABLE_PREFIX "banners WHERE status = 'active' AND available >= 1 ORDER BY RAND() LIMIT 1");
if(
ctype_digit($banner['userid'])) {
    
//show it
} else {
    
//show default


The above code works fine and prints out code when the user's status is active and their available impressions is at least 1. I want to modify it to also check if the user has posted within the past 24 hours. I don't know how to though as I am using my own table in the vbulletin database to store the banner information. As you see above the query that fetches the data I need is querying from the table banners. From my knowledge I would need to fetch the last post time from the lastpostdate column in the user table. But how would I add this to my query so all three of these are factored in when it gets the one random array ($banner[]) from the banners table?

As well I would like to setup the query to also not pick the row in the banners table that matches the vistor's userid (so users do not see their own banners being displayed).

JTyson 10-21-2005 03:31 PM

$vbulletin->userinfo['lastpost']

should give you that info

Nullifi3d 10-21-2005 06:48 PM

Quote:

Originally Posted by JTyson
$vbulletin->userinfo['lastpost']

should give you that info

Not enough info... Seems to be an array? This doesn't seem to answer my question very well.

Andreas 10-21-2005 07:48 PM

PHP Code:

if ($vbulletin->userinfo['lastpost'] > (TIMENOW-86400))
{
// User has posted in the last 24 hours



Nullifi3d 10-27-2005 04:54 PM

Quote:

Originally Posted by Andreas
PHP Code:

if ($vbulletin->userinfo['lastpost'] > (TIMENOW-86400))
{
// User has posted in the last 24 hours



Wouldn't this be how to check if the user that is viewing the page has been online in the last 24 hours? That's not what I need if it is.

Paul M 10-27-2005 05:15 PM

Quote:

Originally Posted by Nullifi3d
Wouldn't this be how to check if the user that is viewing the page has been online in the last 24 hours? That's not what I need if it is.

I would imagine that 'lastpost' is exactly what it says, 'lastactivity' is what you are referring to.

Nullifi3d 10-27-2005 06:50 PM

Yea, but if you take a look at the code in my first post you'll see that I don't need to find out if the current visitor of the page has posted in the last 24 hours. Rather I need to find out if the random user that is generated has posted in the last 24 hours.

Basically my code is a random banner rotator built into vbulletin. I want to change my code which uses sql (in my first post) to randomly pick out a userid from the database so that it randomly picks one out that has posted within the last 24 hours.

Sorry if I'm wrong and just having a brain fart.

Nullifi3d 11-08-2005 08:46 PM

Does anyone have any further comments or suggestions? I need this addition to my mod please.

Andreas 11-08-2005 10:22 PM

[SQL]SELECT userid FROM user WHERE lastpost > UNIX_TIMESTAMP(NOW())-86400 ORDER BY RAND() LIMIT 1[/sql]

If that is what you want

Nullifi3d 11-09-2005 10:20 AM

Quote:

Originally Posted by Andreas
If that is what you want

Yes that is part of what I want. This query would select 1 random user that has posted within the last 24 hours from the mysql table, but the only problem is that this needs to coincide with my sql from the first post which picks 1 random user from a different table in the database.

Is there a way to do this? Maybe having a query store all members that have posted within the last 24 hours in an array or something. Then another query pick 1 by random (according to calls from the query in my first post) from the array. Basically I need to combine these two sql queries together:
[sql]SELECT userid FROM " . TABLE_PREFIX . "user WHERE lastpost > UNIX_TIMESTAMP(NOW())-86400 ORDER BY RAND() LIMIT 1[/sql]
[sql]SELECT userid, title, ext, width, height FROM " . TABLE_PREFIX . "banners WHERE status = 'active' AND available >= 1 ORDER BY RAND() LIMIT 1[/sql]


All times are GMT. The time now is 07:32 AM.

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.01739 seconds
  • Memory Usage 1,745KB
  • 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
  • (3)bbcode_php_printable
  • (4)bbcode_quote_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