Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 07-12-2003, 09:27 PM
Jakeman's Avatar
Jakeman Jakeman is offline
 
Join Date: Nov 2001
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default select query, join question

PHP Code:
// SELECT UPCOMING EVENTS FROM DATABASE
$msc_events $DB_site->query("SELECT*
    FROM msc_events
    LEFT JOIN calendar_events ON (calendar_events.eventid = msc_events.eventid)
    WHERE (UNIX_TIMESTAMP('
$msc_date_extended')) <= UNIX_TIMESTAMP(calendar_events.eventdate)
    AND UNIX_TIMESTAMP(calendar_events.eventdate) <= (UNIX_TIMESTAMP('
$msc_month_extended'))
    AND calendar_events.public = 1
    ORDER BY calendar_events.eventdate ASC
    LIMIT 6
    "
); 
Can this query be modified to select rows from calendar_events that both do and don't have an entry in msc_events? I think the LEFT JOIN is limiting the selection to events that join with the msc_events table.
Reply With Quote
  #2  
Old 07-12-2003, 09:49 PM
Link14716's Avatar
Link14716 Link14716 is offline
 
Join Date: Jun 2002
Location: Georgia, USA
Posts: 2,519
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Wouldn't this work?
[sql]// SELECT UPCOMING EVENTS FROM DATABASE
$msc_events = $DB_site->query("SELECT*
FROM calander_events
LEFT JOIN msc_events ON (msc_events.eventid = calendar_events.eventid)
WHERE (UNIX_TIMESTAMP('$msc_date_extended')) <= UNIX_TIMESTAMP(calendar_events.eventdate)
AND UNIX_TIMESTAMP(calendar_events.eventdate) <= (UNIX_TIMESTAMP('$msc_month_extended'))
AND calendar_events.public = 1
ORDER BY calendar_events.eventdate ASC
LIMIT 6
");[/sql]
Reply With Quote
  #3  
Old 07-12-2003, 09:55 PM
Jakeman's Avatar
Jakeman Jakeman is offline
 
Join Date: Nov 2001
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

oh dude, it's selecting from the msc_events table in the first place. :tard:
Reply With Quote
  #4  
Old 07-12-2003, 11:07 PM
Jakeman's Avatar
Jakeman Jakeman is offline
 
Join Date: Nov 2001
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I tried coming at it from the other direction...

Problem:
If a calendar_events record doesn't have a msc_events record, then $msc_event[eventid] has no value for that record.

PHP Code:
while ($msc_event=$DB_site->fetch_array($msc_events))

... 
Reply With Quote
  #5  
Old 07-15-2003, 02:36 AM
Jakeman's Avatar
Jakeman Jakeman is offline
 
Join Date: Nov 2001
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Maybe some pictures of my tables would help illustrate the situation. Sometimes I confuse problems like this.

I added the msc_events table for my event signup system. An entry is put into the msc_events table when an event is "signupable." If the event creator doesn't want users to be able to signup for the event, then no entry for it is made in the msc_events table.

The calendar_events table is a vBulletin table. I haven't hacked that table at all.

I want to select all public events, linking the two tables by eventid even if the public event in the calendar_events table doesn't have a matching entry in the msc_events table (it isn't "signupable").

The problem I am having right now is that there appears to be no value for eventid when the selected event doesn't have a matching msc_events entry.
Attached Images
File Type: gif msc_events.gif (24.6 KB, 0 views)
Reply With Quote
  #6  
Old 07-15-2003, 02:36 AM
Jakeman's Avatar
Jakeman Jakeman is offline
 
Join Date: Nov 2001
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

second pic
Attached Images
File Type: gif calendar_events.gif (43.7 KB, 0 views)
Reply With Quote
  #7  
Old 07-26-2003, 09:02 PM
Jakeman's Avatar
Jakeman Jakeman is offline
 
Join Date: Nov 2001
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I ended up selecting from the calendar_events table and querying the msc_events table while going through the array of records from the calendar_events table. I am using a lot more queries this way, but it's the only way I could get it to work without modifying the calendar_events table.
Reply With Quote
  #8  
Old 07-27-2003, 10:24 AM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just a heads up Jake. In my PHP book SAMS Learn PHP in 24 hours it has a kind of public events system for a club in the final 2 chapters where a user can sign up and add their club with unlimited events and if the user is guest they can browse through the directory. Are you trying to achieve anything like that?

- miSt
Reply With Quote
  #9  
Old 07-27-2003, 06:25 PM
Jakeman's Avatar
Jakeman Jakeman is offline
 
Join Date: Nov 2001
Posts: 273
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Maybe. I already have mine working though. I added on to vB's calendar so you can create events that people can signup for. I wanted to do this without modifying any vB tables, which lead to problems like what I posted about in this thread... but I got it working.
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:47 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.08213 seconds
  • Memory Usage 2,255KB
  • Queries Executed 12 (?)
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_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (2)postbit_attachment
  • (9)postbit_onlinestatus
  • (9)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
  • postbit_attachment
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete