Page 1 of 1

Please Help Me Filter Results

Posted: Wed Feb 28, 2007 9:33 am
by ORiGIN
Hello, I am trying to make a page where an admin can edit a part of a user. I want the page to first display a list of a certain type of users. So first I just use a while loop:

Code: Select all

include "config.php";
// connect to the mysql server
$link = mysql_connect($server, $db_user2, $db_pass2)
or die ("Could not connect to mysql because ".mysql_error());
	
// select the database
mysql_select_db($database2)
or die ("Could not select database because ".mysql_error());

//If cmd has not been initialized
if(!isset($cmd)) 
{
   //display all the links
   $result = mysql_query("SELECT * FROM smf_members order by ID_GROUP desc"); 
   
   //run the while loop
	   while($r=mysql_fetch_array($result)) 
   { 
      //grab the title and the ID
      $name=$r["MemberClanName"];//take out the title
      $id=$r["ID_MEMBER"];//take out the id
     
	 //make the title a link
      echo "<a href='rpoints.php?cmd=edit&ID_MEMBER=$id'>$name</a>";
      echo "<br>";
    }
}
But I would like it to filter through those results so it only shows users that are in certain groups. I want it to check a row called "ID_GROUPS" and see if the number is a 9 or a 1 and if so display only those, but get rid of the rest.

Is this possible to do, and if so how would I accomplish it?

Thanks

Posted: Wed Feb 28, 2007 9:48 am
by feyd
The question (and answer) has less to do with PHP and more to do with SQL, so moved to Databases.

A brief example:

Code: Select all

SELECT ... WHERE foo IN(3,5)

Posted: Wed Feb 28, 2007 9:49 am
by ORiGIN
Thanks for the info, I have found my answer, I needed to do it like this:

Code: Select all

$result = mysql_query("SELECT * FROM smf_members WHERE ID_GROUP=9 OR ID_Group=1 ORDER BY ID_GROUP desc");
Thanks

Posted: Wed Feb 28, 2007 10:42 am
by mikeq
or you can do it exactly as feyd said

Code: Select all

WHERE id_group IN (1,9)