Michan Posted November 1, 2006 Share Posted November 1, 2006 Hi,I'm trying to display recent forum topics on a homepage. But what if I want to hide topics from more than one forum?[code]$forum = mysql_query('SELECT title, tid FROM ibf_topics WHERE forum_id!= 53 ORDER BY last_post DESC LIMIT 0, 1');[/code]The above code hides any posts from one of the moderator-only forums, but there are more than one, and I need to hide them all.The other forums I need to hide are: 85, 86, 88, 90, 93How can I hide all of these? I've been looking around for a solution for ages, but can't find anything. My guess is that it's pretty straightforward, and I'm just missing something. XDMany thanks~! Quote Link to comment https://forums.phpfreaks.com/topic/25866-more-than-one-attribute-for-where/ Share on other sites More sharing options...
roopurt18 Posted November 1, 2006 Share Posted November 1, 2006 I'm going to guess that the forum_id column is the id of the thread and 85, 86, 88, 90, and 93 are threads you'd like to hide? Quote Link to comment https://forums.phpfreaks.com/topic/25866-more-than-one-attribute-for-where/#findComment-118129 Share on other sites More sharing options...
Michan Posted November 1, 2006 Author Share Posted November 1, 2006 forum_id defines the forum (for example, "Mods Lounge" or "Senior Lounge").85, 86, 88, 90, and 93 are the forums I'd like to hide in addition to 53.Thanks! ;D Quote Link to comment https://forums.phpfreaks.com/topic/25866-more-than-one-attribute-for-where/#findComment-118133 Share on other sites More sharing options...
roopurt18 Posted November 1, 2006 Share Posted November 1, 2006 How does your application determine that 85, 86, 88, 90, 93, and 53 are the forum IDs to hide?I know you can look at the MySQL table and pick them out easily, but how does your program know? Quote Link to comment https://forums.phpfreaks.com/topic/25866-more-than-one-attribute-for-where/#findComment-118136 Share on other sites More sharing options...
Michan Posted November 1, 2006 Author Share Posted November 1, 2006 Well right now, I'm just using the WHERE function to !hide any result which has a forum_id of '53', but I'm hoping to be able to hide a result with a different forum_id, as well as that. Quote Link to comment https://forums.phpfreaks.com/topic/25866-more-than-one-attribute-for-where/#findComment-118175 Share on other sites More sharing options...
roopurt18 Posted November 1, 2006 Share Posted November 1, 2006 I understand that. The question I'm asking is how does your program know which IDs are the ones to hide?You can use this MySQL statement:SELECT title, tid FROM ibf_topics WHERE forum_id != 53 AND forum_id != 85 AND forum_id != 86And so on.Or you can use:'SELECT title, tid FROM ibf_topics WHERE forum_id NOT IN(53, 85, 86, 88, 90, 93)But my question is how does your program know to use 53, 85, 86, 88, 90, and 93?How does it know that 33 should or should not be hidden? Quote Link to comment https://forums.phpfreaks.com/topic/25866-more-than-one-attribute-for-where/#findComment-118177 Share on other sites More sharing options...
Michan Posted November 2, 2006 Author Share Posted November 2, 2006 Thanks for your help Roopurt.I'm not sure I understand your question, however.Each topic is a row in that table, and it's just selecting everything but 53 (with the != not equal to), so it just returns every other topic (including 33).Sorry if I haven't got your question, but I'm still very new to PHP (and also it's 3:30 AM XD), but your help is exactly what I was looking for. Thank you very much :) Quote Link to comment https://forums.phpfreaks.com/topic/25866-more-than-one-attribute-for-where/#findComment-118233 Share on other sites More sharing options...
Skatecrazy1 Posted November 2, 2006 Share Posted November 2, 2006 just use a comma to separate, likeWHERE `field` != 'value', `secondfield` != 'secondexcludedvalue', `third` != 'thirdval'and so on Quote Link to comment https://forums.phpfreaks.com/topic/25866-more-than-one-attribute-for-where/#findComment-118244 Share on other sites More sharing options...
roopurt18 Posted November 2, 2006 Share Posted November 2, 2006 You can't comma separate a WHERE clause as far as I know. Quote Link to comment https://forums.phpfreaks.com/topic/25866-more-than-one-attribute-for-where/#findComment-118248 Share on other sites More sharing options...
Daniel0 Posted November 2, 2006 Share Posted November 2, 2006 Try this: [code]<?php$hide_ids = array(85,86,88,90,93);$where = "forum_id!='".join("' AND forum_id!='",$hide_ids)."'";$forum = mysql_query("SELECT title, tid FROM ibf_topics WHERE {$where} ORDER BY last_post DESC LIMIT 0, 1");?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25866-more-than-one-attribute-for-where/#findComment-118271 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.