vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Check this query please (https://vborg.vbsupport.ru/showthread.php?t=68447)

Logikos 08-17-2004 05:51 PM

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

Colin F 08-17-2004 06:27 PM

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 

");

Logikos 08-17-2004 06:45 PM

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

Modin 08-17-2004 10:25 PM

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)

Logikos 08-18-2004 03:44 AM

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



All times are GMT. The time now is 02:45 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.01070 seconds
  • Memory Usage 1,741KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete