Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
  #1  
Old 01-23-2007, 05:27 AM
harmor19 harmor19 is offline
 
Join Date: Apr 2005
Posts: 1,324
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default a tough query

I need help writing a query.

In the "user" table I have "planid"
I want to link that to a table named "hosting_plans".
In "hosting_plans" I have "subscriptionid".
I want to link that to the table "subscriptionlog".

Then I'll have to write up a cron that will check if the user still has the subscription which I also don't know how to write but I'll look at others for an idea.
Reply With Quote
  #2  
Old 01-23-2007, 05:57 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So um... what data do you need? Just the columns listed above? Are you showing users that ARE subscribed or those who are not? (etc)

This might get you started... need more info though:
Code:
SELECT
	u.userid,
	u.username,
	u.planid,
	p.title as planname,
	h.title as hostname,
	sl.status,
	sl.regdate,
	sl.expirydate
	
FROM user as u
LEFT JOIN hosting_pans as p on (u.planid = p.planid)
LEFT JOIN subscription as s on (h.subscriptionid = s.subscriptionid)
LEFT JOIN subscriptionlog as sl on (sl.subscriptionid = s.subscriptionid)

WHERE u.planid > 0
Then when you process through the results, you can use the dates to do whatever. Or, use the date in the query to restrict it to expired or valid subscriptions.
Reply With Quote
  #3  
Old 01-23-2007, 06:09 AM
harmor19 harmor19 is offline
 
Join Date: Apr 2005
Posts: 1,324
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I want to show who are not subscribed. I edited the code to show "sl.status = 1" but it doesn't return any rows. I know that there is row in the "subscriptionlog" table with the "status" using the value "1".
What I want it to do is check if the user's subscription has expired.

Code:
SELECT
u.userid,
u.username,
u.planid,
p.title as planname,
p.title as hostname,
sl.status,
sl.regdate,
sl.expirydate

FROM user as u
LEFT JOIN hosting_plans as p on (u.planid = p.planid)
LEFT JOIN subscription as s on (p.subscriptionid = s.subscriptionid)
LEFT JOIN subscriptionlog as sl on (sl.subscriptionid = s.subscriptionid)

WHERE u.planid > 0 && sl.status = 1
Reply With Quote
  #4  
Old 01-23-2007, 06:10 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Not subscribed, as in they used to be? Add "&& sl.expirydate < " . TIMENOW . "
Reply With Quote
  #5  
Old 01-23-2007, 06:52 AM
harmor19 harmor19 is offline
 
Join Date: Apr 2005
Posts: 1,324
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you. Now I have to put it in PHP form but I can manage that.
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 04:55 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.03991 seconds
  • Memory Usage 2,191KB
  • Queries Executed 13 (?)
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)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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_postinfo_query
  • fetch_postinfo
  • 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