yakk0 Posted November 19, 2008 Share Posted November 19, 2008 $result = mysql_query("SELECT * FROM members WHERE Clan='Zenith' ORDER BY Level DESC,Members ASC"); I would like to know if I can add more then one key word when Its using "Where" Statement. Like I want it to search for Clan='Zenith' but also search for another Clan='something'. Would it be possible for it to search more then one key word and list them all in one? Quote Link to comment https://forums.phpfreaks.com/topic/133347-question-about-where-statement/ Share on other sites More sharing options...
premiso Posted November 19, 2008 Share Posted November 19, 2008 Either the IN operator or the OR operator. IE: $result = mysql_query("SELECT * FROM members WHERE Clan='Zenith' OR Clan='something' OR Clan='somethingelse'ORDER BY Level DESC,Members ASC"); OR $result = mysql_query("SELECT * FROM members WHERE Clan IN('Zenith', 'something', 'somethingelse') ORDER BY Level DESC,Members ASC"); Quote Link to comment https://forums.phpfreaks.com/topic/133347-question-about-where-statement/#findComment-693511 Share on other sites More sharing options...
RIRedinPA Posted November 19, 2008 Share Posted November 19, 2008 I didn't know about the IN statement, that's a nice typing saver! Quote Link to comment https://forums.phpfreaks.com/topic/133347-question-about-where-statement/#findComment-693528 Share on other sites More sharing options...
premiso Posted November 19, 2008 Share Posted November 19, 2008 I didn't know about the IN statement, that's a nice typing saver! Works even better if your clan name list is in an array. $clanname = array("Zenith", "Exodus", "Paradon"); $clans = "'" . implode("', '", $clanname) . "'"; $result = mysql_query("SELECT * FROM members WHERE Clan IN(" . $clans . ") ORDER BY Level DESC,Members ASC"); Pretty fancy stuff =) EDIT: A different way to do the above $clanname = array("Zenith", "Exodus", "Paradon"); $clans = implode("', '", $clanname); $result = mysql_query("SELECT * FROM members WHERE Clan IN('" . $clans . "') ORDER BY Level DESC,Members ASC"); // note the added single quotes inside the in That also works well, just thought of it so figured I would also post it. Without the singlequotes MySQL would throw an error. Quote Link to comment https://forums.phpfreaks.com/topic/133347-question-about-where-statement/#findComment-693535 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.