1

$sql_where = ''; $exclude = '30,35,36,122,123,124,125';

if($exclude != '') 
{     
    $exclude_forums = explode(',', $exclude); 
    foreach ($exclude_forums as $id) 
    { 
        if ($id > 0) 
        { 
            $sql_where = ' AND forum_id <> ' . trim($id); 
        } 
    }
} 

$sql = 'SELECT topic_title, forum_id, topic_id, topic_type, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour, topic_last_post_time
   FROM ' . TOPICS_TABLE . '
   WHERE topic_status <> 2
      AND topic_approved = 1
      ' . $sql_where . '
   ORDER BY topic_time DESC';

The above code i use to exclude the id of forum to be displayed on sql queries.

Why doesn't it work and still display it?

Any solution

3 Answers 3

4

You're missing the dot before =

$sql_where .= ' AND forum_id <> ' . trim($id);
Sign up to request clarification or add additional context in comments.

Comments

1

You are overwriting your $sql_where variable on each loop iteration. You probably want to be using the concatenation operator (.) in the middle of your code instead:

if ($id > 0) 
{ 
    $sql_where .= ' AND forum_id <> ' . trim($id);
}

Note the change of the = to .=

Comments

0
if($exclude != '') $sql_where = 'AND forum_id NOT IN ($exclude); 

instead of all this messy code :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.