Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 06-21-2003, 04:24 PM
SaintDog SaintDog is offline
 
Join Date: Nov 2001
Location: Tennessee
Posts: 1,975
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Getting MySQL's JOIN to work -- Please Help

I am working on a small hack for vBulletin and need to get a JOIN query to output the right data depending on a few things.

To start, I have 2 tables, one named hd_posts and the other hd_replies. What I want to do is when a post is shown, I want the replies with the matching ID to be show as well, if any are available.

Right now, I can show the post just fine, but I cannot create a query that works correctly so that I can call the matching replies as well.

I have outlined the table structure of each below:

hd_posts:

id, name, subtitle, subdate, subtime, message, and hashid

hd_replies:

id, tid, name, subtitle, subdate, subtime, message, and hashid

The tid is the ID of the matching post.

If anyone could help me get this working, I would greatly appreciate it. I am confused on this one query and cannot get it working at all.

Thanks in advance for anyone kind enough to take the time to help!

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

[sql]SELECT post.*, reply.name as replyname, reply.subtitle as replysubtitle.......
FROM hd_posts as post
LEFT JOIN hd_replies as reply ON (post.id = reply.tid)[/sql]

this should do it..
Reply With Quote
  #3  
Old 06-22-2003, 06:36 AM
SaintDog SaintDog is offline
 
Join Date: Nov 2001
Location: Tennessee
Posts: 1,975
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Xenon, but that does not seem to work, or I am just doing something wrong (the second part is probably the problem ).

Here is what I have, could you please tell me if there is a problem with this?

PHP Code:
$listreply = ("SELECT post.*, reply.name as replyname, reply.subtitle as replysubtitle
FROM hd_posts as post
LEFT JOIN hd_replies as reply ON (post.id = reply.tid)"
);

while(
$listreplies $DB_site->fetch_array($listreply)) {

    eval(
'$viewreplies .= "' fetch_template('viewreplies') . '";');


Using the above I get the following output at the top of the page:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /path/to/includes/db_mysql.php on line 250
Reply With Quote
  #4  
Old 06-22-2003, 10:12 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

it was just an example, not the full query, you have to add some reply fields at the end (folow my example of subtitle )

and then the code itself you forgot an $DB_site

PHP Code:
$listreply $DB_site->query("SELECT post.*, reply.name as replyname, reply.subtitle as replysubtitle 
FROM hd_posts as post 
LEFT JOIN hd_replies as reply ON (post.id = reply.tid)"
); 

while(
$listreplies $DB_site->fetch_array($listreply)) { 

    eval(
'$viewreplies .= "' fetch_template('viewreplies') . '";'); 


then be sure your viewreplies template does use the correct varnames
Reply With Quote
  #5  
Old 06-22-2003, 11:14 AM
SaintDog SaintDog is offline
 
Join Date: Nov 2001
Location: Tennessee
Posts: 1,975
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am not quite sure what else to add, I am just used to basic stuff since I am not that much of a programmer (as you can probably tell ).

What else would I need to add (as you mentioned above) to complete the query (I didn't add the $DB_site-> though it is in the original query, just left it off here).
Reply With Quote
  #6  
Old 06-22-2003, 12:34 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hmm ok, then the long method

PHP Code:
$listreply $DB_site->query("
SELECT post.*, reply.name as replyname, reply.subtitle as replysubtitle, reply.subtime as replysubtime, reply.message as replymessage, reply.hashid as replyhashid 
FROM hd_posts as post 
LEFT JOIN hd_replies as reply ON (post.id = reply.tid)
"
); 

while(
$listreplies $DB_site->fetch_array($listreply)) 


    eval(
'$viewreplies .= "' fetch_template('viewreplies') . '";'); 


and be sure as said $listreplies[reply....] is in your templates
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 12:39 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.06124 seconds
  • Memory Usage 2,210KB
  • 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
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)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