Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 11-21-2006, 10:03 PM
Slyfox1 Slyfox1 is offline
 
Join Date: Jul 2006
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Adding WHERE statement to a DB query

Hi,

I'm using a HACK that pulls threads from the forums table and displays the latest X threads.

There are permissions on the HACk, but there's no way to exclude specific forums.

So, I was hoping someone might be able to look at the section of code below and perhaps suggest a way to either exclude specific forums, or add forums to the viewing list. I would be happy enough to add 50 forum ID's to restrict one forum.

Cheers

PHP Code:
$latestthreads $db->query_read("
                            SELECT thread.*, thread.open AS open, forum.title as forumname, forum.forumid as forumid, icon.iconpath AS iconpath, icon.iconid,
IF (thread.iconid=0, 'images/icons/icon1.gif', icon.iconpath)as icon
                            FROM " 
TABLE_PREFIX "thread as thread
                            LEFT JOIN " 
TABLE_PREFIX "forum as forum ON (forum.forumid = thread.forumid)
LEFT JOIN " 
TABLE_PREFIX "icon as icon ON (icon.iconid = thread.iconid)
                            
$excludedthreads
                            ORDER BY thread.lastpost DESC
                            LIMIT 0,
$number
                           "
); 
Reply With Quote
  #2  
Old 11-21-2006, 10:07 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What is $excludedthreads ? I'm assuming it contains "WHERE" - so make sure that its either always there or make it that way.

Here would be the condition to limit it to certain forums: [sql]thread.forumid IN (1, 2, 3)[/sql] and to exclude: [sql]NOT (thread.forumid IN (1, 2, 3))[/sql]You're probably best off loading them into an array and imploding them inside the query
PHP Code:
$forums = array(123, ...);
$forumlist implode(','$forums); 
then use [sql]thread.forumid IN ($forumlist)[/sql]
Reply With Quote
  #3  
Old 11-21-2006, 10:40 PM
Slyfox1 Slyfox1 is offline
 
Join Date: Jul 2006
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi and thanks for your reply.

I should have posted the entire code to make sure the addition fits in. I tried to add the statement(s) below and it failed My fault for not knowing where to add the code.

Here's the entire section
PHP Code:
$number $vbulletin->options[latest_x_threads_number];

        foreach (
$vbulletin->userinfo['forumpermissions'] AS $forumid => $fperms)
            {
                if (!(
$fperms $vbulletin->bf_ugp_forumpermissions['canview']) OR !($fperms $vbulletin->bf_ugp_forumpermissions['cansearch']) OR !verify_forum_password($forumid$forum['password'], false) OR !($vbulletin->forumcache[$forumid]['options'] & $vbulletin->bf_misc_forumoptions['indexposts']))
                {
                    
$excludelist .= ",$forumid";
                }
                else if ((!
$vbulletin->GPC['titleonly'] OR $vbulletin->GPC['showposts']) AND !($fperms $vbulletin->bf_ugp_forumpermissions['canviewthreads']))
                {    
// exclude forums that have canview but no canviewthreads if this is a post search
                    
$excludelist .= ",$forumid";
                }
            }
if(
$excludelist != ''){
$excludedthreads "WHERE forum.forumid NOT IN (0$excludelist)";
}
$latestthreads $db->query_read("
                            SELECT thread.*, thread.open AS open, forum.title as forumname, forum.forumid as forumid, icon.iconpath AS iconpath, icon.iconid,
IF (thread.iconid=0, 'images/icons/icon1.gif', icon.iconpath)as icon
                            FROM " 
TABLE_PREFIX "thread as thread
                            LEFT JOIN " 
TABLE_PREFIX "forum as forum ON (forum.forumid = thread.forumid)
                            
LEFT JOIN " 
TABLE_PREFIX "icon as icon ON (icon.iconid = thread.iconid)
                            
$excludedthreads
                            ORDER BY thread.lastpost DESC
                            LIMIT 0,
$number
                           "
);

while (
$thread $db->fetch_array($latestthreads))
{
if (
$thread['replycount'] >= $vbulletin->options['hotnumberposts'] OR  $thread['views'] >= $vbulletin->options['hotnumberviews'])
{
$thread['statusicon'] = "_hot_new";
}

if (
$thread['open'] == '0')
{
$thread['statusicon'] = "_lock";

       if (
$thread['replycount'] >= $vbulletin->options['hotnumberposts'] OR  $thread['views'] >= $vbulletin->options['hotnumberviews'])
       {
       
$thread['statusicon'] = "_hot_lock";
       }
}
eval(
'$latest_x_threads_bits .= "' fetch_template('latest_x_threads_bits') . '";');
}
eval(
'$latest_x_threads = "' fetch_template('latest_x_threads') . '";'); 
Reply With Quote
  #4  
Old 11-21-2006, 10:49 PM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try this, and just add to the $excludearray at the beginning to exclude more forums or the $includeforums to only show those forums,
PHP Code:
$number $vbulletin->options['latest_x_threads_number'];

$conditions = array('1=1');
$excludearray();
$includeforums = array(123);

foreach (
$vbulletin->userinfo['forumpermissions'] AS $forumid => $fperms)
{
    if (
        !(
$fperms $vbulletin->bf_ugp_forumpermissions['canview']) OR
        !(
$fperms $vbulletin->bf_ugp_forumpermissions['cansearch']) OR
        !
verify_forum_password($forumid$forum['password'], false) OR
        !(
$vbulletin->forumcache[$forumid]['options'] & $vbulletin->bf_misc_forumoptions['indexposts'])
    )
    {
        
$excludearray[] = $forumid;
    }

    else if (
        (!
$vbulletin->GPC['titleonly'] OR $vbulletin->GPC['showposts']) AND
        !(
$fperms $vbulletin->bf_ugp_forumpermissions['canviewthreads'])
    )
    {
        
$excludearray[] = $forumid;
    }
}

if (!empty(
$excludelist))
{
    
$conditions[] = 'forum.forumid NOT IN (' implode(','$excludearray) . ')';
}

if (!empty(
$includeforums))
{
    
$conditions[] = 'forum.forumid IN (' implode(','$includeforums) . ')';
}

$latestthreads $db->query_read("
    SELECT thread.*, thread.open AS open, forum.title as forumname, forum.forumid as forumid,
        icon.iconpath AS iconpath, icon.iconid, IF (thread.iconid=0, 'images/icons/icon1.gif', icon.iconpath)as icon

    FROM " 
TABLE_PREFIX "thread as thread
    LEFT JOIN " 
TABLE_PREFIX "forum as forum ON (forum.forumid = thread.forumid)
    LEFT JOIN " 
TABLE_PREFIX "icon as icon ON (icon.iconid = thread.iconid)

    WHERE " 
implode(' and '$conditions) . "

    ORDER BY thread.lastpost DESC
    LIMIT 0,
$number
"
);

while (
$thread $db->fetch_array($latestthreads))
{
    if (
        
$thread['replycount'] >= $vbulletin->options['hotnumberposts'] OR
        
$thread['views'] >= $vbulletin->options['hotnumberviews']
    )
    {
        
$thread['statusicon'] = "_hot_new";
    }


    if (!
$thread['open'])
    {
        
$thread['statusicon'] = "_lock";

        if (
            
$thread['replycount'] >= $vbulletin->options['hotnumberposts'] OR
            
$thread['views'] >= $vbulletin->options['hotnumberviews'])
        {
            
$thread['statusicon'] = "_hot_lock";
        }
    }

    eval(
'$latest_x_threads_bits .= "' fetch_template('latest_x_threads_bits') . '";');
}

eval(
'$latest_x_threads = "' fetch_template('latest_x_threads') . '";'); 
untested
Reply With Quote
  #5  
Old 11-22-2006, 12:24 AM
Slyfox1 Slyfox1 is offline
 
Join Date: Jul 2006
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hey,

I tried to remove the Included forums and add the ones to the exclude and got a blank white page, I then tried to code as is and got the same blank page
Reply With Quote
  #6  
Old 11-22-2006, 12:27 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

My Apologies... near the top, change this
PHP Code:
$excludearray(); 
to
PHP Code:
$excludearray = array(); 
Reply With Quote
  #7  
Old 11-22-2006, 12:48 AM
Slyfox1 Slyfox1 is offline
 
Join Date: Jul 2006
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

OK, added the changes and no more blank pages. Removed the entries in the Include section and added one subforum to the exclude list, but posts in this subforum still appear.

Is it different for subforums?

Thanks again.,
Reply With Quote
  #8  
Old 11-22-2006, 01:09 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can you post your exact code here, thanks.
Reply With Quote
  #9  
Old 11-22-2006, 01:56 AM
Slyfox1 Slyfox1 is offline
 
Join Date: Jul 2006
Posts: 54
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$number $vbulletin->options['latest_x_threads_number'];

$conditions = array('1=1');
$excludearray = array(18);
$includeforums = array();

foreach (
$vbulletin->userinfo['forumpermissions'] AS $forumid => $fperms)
{
    if (
        !(
$fperms $vbulletin->bf_ugp_forumpermissions['canview']) OR
        !(
$fperms $vbulletin->bf_ugp_forumpermissions['cansearch']) OR
        !
verify_forum_password($forumid$forum['password'], false) OR
        !(
$vbulletin->forumcache[$forumid]['options'] & $vbulletin->bf_misc_forumoptions['indexposts'])
    )
    {
        
$excludearray[] = $forumid;
    }

    else if (
        (!
$vbulletin->GPC['titleonly'] OR $vbulletin->GPC['showposts']) AND
        !(
$fperms $vbulletin->bf_ugp_forumpermissions['canviewthreads'])
    )
    {
        
$excludearray[] = $forumid;
    }
}

if (!empty(
$excludelist))
{
    
$conditions[] = 'forum.forumid NOT IN (' implode(','$excludearray) . ')';
}

if (!empty(
$includeforums))
{
    
$conditions[] = 'forum.forumid IN (' implode(','$includeforums) . ')';
}

$latestthreads $db->query_read("
    SELECT thread.*, thread.open AS open, forum.title as forumname, forum.forumid as forumid,
        icon.iconpath AS iconpath, icon.iconid, IF (thread.iconid=0, 'images/icons/icon1.gif', icon.iconpath)as icon

    FROM " 
TABLE_PREFIX "thread as thread
    LEFT JOIN " 
TABLE_PREFIX "forum as forum ON (forum.forumid = thread.forumid)
    LEFT JOIN " 
TABLE_PREFIX "icon as icon ON (icon.iconid = thread.iconid)

    WHERE " 
implode(' and '$conditions) . "

    ORDER BY thread.lastpost DESC
    LIMIT 0,
$number
"
);

while (
$thread $db->fetch_array($latestthreads))
{
    if (
        
$thread['replycount'] >= $vbulletin->options['hotnumberposts'] OR
        
$thread['views'] >= $vbulletin->options['hotnumberviews']
    )
    {
        
$thread['statusicon'] = "_hot_new";
    }


    if (!
$thread['open'])
    {
        
$thread['statusicon'] = "_lock";

        if (
            
$thread['replycount'] >= $vbulletin->options['hotnumberposts'] OR
            
$thread['views'] >= $vbulletin->options['hotnumberviews'])
        {
            
$thread['statusicon'] = "_hot_lock";
        }
    }

    eval(
'$latest_x_threads_bits .= "' fetch_template('latest_x_threads_bits') . '";');
}

eval(
'$latest_x_threads = "' fetch_template('latest_x_threads') . '";'); 
Reply With Quote
  #10  
Old 11-22-2006, 02:03 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Typo, change this
PHP Code:
if (!empty($excludelist)) 
with this
PHP Code:
if (!empty($excludearray)) 
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 05:22 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.04311 seconds
  • Memory Usage 2,329KB
  • 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
  • (9)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete