Please Help Me Filter Results

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ORiGIN
Forum Newbie
Posts: 20
Joined: Sat Nov 11, 2006 11:17 pm

Please Help Me Filter Results

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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)
ORiGIN
Forum Newbie
Posts: 20
Joined: Sat Nov 11, 2006 11:17 pm

Post 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
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

or you can do it exactly as feyd said

Code: Select all

WHERE id_group IN (1,9)
Post Reply