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 07-21-2004, 01:33 PM
edschaum's Avatar
edschaum edschaum is offline
 
Join Date: Jul 2004
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Trying to change thread query to accept more dates

I'm trying to change the query listed below. Right now, the query returns threads based on a single date. I want the query to accept a separate date for each forum, which I've already stored in another table.

I think the line that has to be changed is "AND thread.lastpost >=$datecut"

Instead of using the date in $datecut, I want to pull a separate date from another table called lastreads which contains the following fields:
lastreads_id, lr_member, lr_forum and lr_lastviewed. (key to fields: lastreads_id is an autoincrement index, lr_member contains a userid, lr_forum contains a forumid, and lastviewed contains the "timenow" that lr_member last read lr_forum.

I want to pull the value in lr_lastviewed where forumid = lr_forum and $bbsuserinfo('userid') = lr_member and plug that value into the query so that it uses the separate date that has been stored for each forum.

Original Query that I want to change:
Code:
$threads = $DB_site->query("
		SELECT threadid
		FROM " . TABLE_PREFIX . "thread AS thread
		LEFT JOIN " . TABLE_PREFIX . "deletionlog AS delthread ON(delthread.primaryid = thread.threadid AND delthread.type = 'thread')
		WHERE forumid IN(" . implode(', ', $forumids) . ")
		AND thread.lastpost >= $datecut
		AND visible = 1
		AND delthread.primaryid IS NULL
		AND sticky IN (0,1)
		ORDER BY lastpost DESC
		LIMIT $vboptions[maxresults]
	");
Can someone help me revise this query so that it does what I want?

thanks,

Ed
Reply With Quote
  #2  
Old 07-21-2004, 02:09 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hmm i think this should work, but you have t make sure the entries for lastreads do exist!

PHP Code:
$threads $DB_site->query("
        SELECT threadid
        FROM " 
TABLE_PREFIX "thread AS thread
        LEFT JOIN " 
TABLE_PREFIX "deletionlog AS delthread ON(delthread.primaryid = thread.threadid AND delthread.type = 'thread')
        LEFT JOIN " 
TABLE_PREFIX "lastreads AS lastreads ON(lastreads.lr_forum = thread.forumid AND lr_member = $bbuserinfo[userid])
        WHERE forumid IN(" 
implode(', '$forumids) . ")
        AND thread.lastpost >= lastreads.lr_lastviewed
        AND visible = 1
        AND delthread.primaryid IS NULL
        AND NOT lastreads.lastreads_id IS NULL
        AND sticky IN (0,1)
        ORDER BY lastpost DESC
        LIMIT 
$vboptions[maxresults]
    "
); 
Reply With Quote
  #3  
Old 07-21-2004, 03:02 PM
edschaum's Avatar
edschaum edschaum is offline
 
Join Date: Jul 2004
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the very fast response. That query loooks like it makes the exact request that I want, but it's not returning any threads.

I'm sure it's something I haven't quite figured out yet on my end, so I'll study it for a while to see if I can figure out what I'm doing wrong.

Thanks again, I'll let you know if I get this working, it's the final piece I need to change the entire Mark Read system over to being persistant.

Ed
Reply With Quote
  #4  
Old 07-21-2004, 03:56 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

as said, are you sure there are already entries in the lastreads table?

because, it won't get any thread, if there is no entry for the actual browsing user
Reply With Quote
  #5  
Old 07-21-2004, 04:18 PM
edschaum's Avatar
edschaum edschaum is offline
 
Join Date: Jul 2004
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, the data already exists in lastreads. In addition to a visual check of the table, I also ran the following test query:
Code:
//go through list of forums already loaded into $forumarray previously
While ($edforum = $DB_site->fetch_array($forumarray))
{
$qsforumid = $edforum['forumid'];

$edlastread = $DB_site->query_first("SELECT lr_lastviewed FROM " . TABLE_PREFIX . "lastreads 
WHERE lr_member = $bbuserinfo[userid] and lr_forum=$qsforumid");

$viewed = $edlastread['lr_lastviewed'];

echo 'forumid = ' . $qsforumid; 
echo ' date = ' . $viewed . '<br>';

}
returns a result like this:

forumid = 1 date = 1090252769
forumid = 2 date = 1090252769
forumid = 3 date = 1090252769
forumid = 4 date = 1090252769
forumid = 5 date = 1090252769
forumid = 6 date = 1090253340
forumid = 7 date = 1090252769
.
.
The values returned are the correct values stored for my userid/forum.

I'm sure it's just my thick head getting in the way of making this work. I'll keep messing around with it and see if I can figure out what I'm doing wrong.
Reply With Quote
  #6  
Old 07-21-2004, 11:24 PM
edschaum's Avatar
edschaum edschaum is offline
 
Join Date: Jul 2004
Posts: 38
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Xenon
hmm i think this should work, but you have t make sure the entries for lastreads do exist!

I got it working! I removed the "AND NOT lastreads.lastreads_id IS NULL" and it started working right away. I'll figure out how to deal with error conditions elsewhere, that's unimportant compared to this leap forward.

I can't thank you enough for this, it is the key to making the hack useful, and you've made it possible. I could never have put that join together even if I stared at the query for a year.

Ed
Reply With Quote
  #7  
Old 07-22-2004, 07:44 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default



glad i could help

Good you figured out how to solve it. Not that i see right now, why that line doesn't fit, but well
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 07:10 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.04843 seconds
  • Memory Usage 2,229KB
  • 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
  • (2)bbcode_code
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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