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 08-17-2004, 05:51 PM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Check this query please

PHP Code:
        $info $DB_site->query("
                SELECT
                        thread.threadid as threadid,thread.title as title,thread.forumid as forumid,
                        thread.postusername as postusername,thread.postuserid as postuserid,thread.dateline as dateline,
                        thread.views as views,thread.replycount as replycount,forum.title as forumtitle
                FROM thread AS thread
                WHERE forumid IN(
$id)
                ORDER BY threadid DESC
        "
); 
That query is basicly taking alot of info from the table thread. I wanted to grab the forum name from the database. Seeing the thread table don't have the title of forums just ids. I tried getting it from the forum table in the same query. I just added a "forum.title as forumtitle" But i get an sql error

mysql error: Unknown table 'forum' in field list

Any ideas how to grab info from to tables in the same query? Thanks a bunch
Reply With Quote
  #2  
Old 08-17-2004, 06:27 PM
Colin F's Avatar
Colin F Colin F is offline
 
Join Date: Jul 2004
Location: Switzerland
Posts: 1,551
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try a JOIN:

PHP Code:
$info $DB_site->query(
                SELECT 
                        thread.threadid as threadid,thread.title as title,thread.forumid as forumid, 
                        thread.postusername as postusername,thread.postuserid as postuserid,thread.dateline as dateline, 
                        thread.views as views,thread.replycount as replycount,forum.title as forumtitle 
                FROM thread AS thread
LEFT JOIN " 
TABLE_PREFIX "forum AS forum ON (forum.forumid = thread.forumid)
                WHERE forumid IN(
$id
                ORDER BY threadid DESC 
");
Reply With Quote
  #3  
Old 08-17-2004, 06:45 PM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ya i tried the LEFT JOIN " . TABLE_PREFIX . "forum AS forum ON (forum.forumid = thread.forumid)

But i kept getting a mysql error: Column: 'forumid' in where clause is ambiguous
Reply With Quote
  #4  
Old 08-17-2004, 10:25 PM
Modin Modin is offline
 
Join Date: Jun 2004
Posts: 162
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just need to specify where the forumid field is from. So this will work.
[SQL]
$info = $DB_site->query("
SELECT
thread.threadid as threadid,thread.title as title, thread.forumid as forumid,
thread.postusername as postusername,thread.postuserid as postuserid,thread.dateline as dateline,
thread.views as views,thread.replycount as replycount,forum.title as forumtitle
FROM thread AS thread
LEFT JOIN " . TABLE_PREFIX . "forum AS forum ON (forum.forumid = thread.forumid)
WHERE forum.forumid IN($id)
ORDER BY threadid DESC
[/SQL]

However, if this script has access to $forumcache you don't need to select the forum title from the table, and therefore no need for a join.

such as...
PHP Code:
$info $DB_site->query("
                SELECT
                        thread.threadid as threadid,thread.title as title, thread.forumid as forumid,
                        thread.postusername as postusername,thread.postuserid as postuserid,thread.dateline as dateline,
                        thread.views as views,thread.replycount as replycount,
                FROM thread AS thread
                WHERE thread.forumid IN(
$id)
                ORDER BY threadid DESC"
); 

while(
$item $DB_site->fetch_array($info))
{
    
$item['forumtitle'] = $forumcache["$item[forumid]"]['title'];
    
//rest of your code

Both will have the same results, but the second would be quicker because there's no join. (this is of course if the script has access to $forumcache)
Reply With Quote
  #5  
Old 08-18-2004, 03:44 AM
Logikos Logikos is offline
 
Join Date: Jan 2003
Posts: 2,924
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok this is what i placed

PHP Code:
        $info $DB_site->query("
                SELECT
                        thread.threadid,thread.title,thread.forumid,thread.postusername,thread.postuserid,
                        thread.dateline,thread.views,thread.replycount,forum.title as forumtitle
                FROM thread AS thread
                LEFT JOIN " 
TABLE_PREFIX "forum AS forum ON (forum.forumid = thread.forumid)
                WHERE forumid IN(
$id)
                ORDER BY threadid DESC
        "
); 
And i get this

Quote:
mysql error: Column: 'forumid' in where clause is ambiguous

mysql error number: 1052
Fixed it. Had to chage the WHERE statement to
PHP Code:
WHERE thread.forumid IN($id
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 02:05 PM.


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.03423 seconds
  • Memory Usage 2,214KB
  • 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
  • (5)bbcode_php
  • (1)bbcode_quote
  • (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_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