queries with exceptions?

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
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

queries with exceptions?

Post by irealms »

I want to do a query to pull out all users except the current user. I've looked on mysql.com and can't find a command that does it.
My query is :

Code: Select all

<?php

echo '<p class="main">Send a message.</p>';
$grabusers = "SELECT username FROM users WHERE groupname='$_SESSION[groupname]'";
$grabq = mysql_query($grabusers, $db_conn) or die("Query grabusers failed".mysql_error());
echo '<p class="main">';
echo '<table class="main" cellspacing="5" cellpadding="5" border="0">';
echo '<form method="post" action="index.php?page=e-new">';
echo '<tr><td><b>Recipitent:</b></td>';
echo '<td><select name="recip" id="recip" class="form">';
echo '<option value="blank">-select a user-</option>';
while ($grow = mysql_fetch_assoc($grabq))
{
	echo '<option value="'.$grow['username'].'">'.$grow['username'].'</option>';
}
echo '</select></td></tr>';

?>
as you can see i'm populating a form field with users to choose as a mail recipitent , i want it to show all apart from current user. something in the where clause maybe?
User avatar
greenhorn666
Forum Commoner
Posts: 87
Joined: Thu Aug 14, 2003 7:14 am
Location: Brussels, Belgium

Post by greenhorn666 »

Code: Select all

$grabusers = "SELECT username 
        FROM users 
        WHERE groupname='$_SESSION[groupname]' 
            AND username != '$_SESSION[username]'";
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

Post by irealms »

ah thanks, should have thought of that
User avatar
greenhorn666
Forum Commoner
Posts: 87
Joined: Thu Aug 14, 2003 7:14 am
Location: Brussels, Belgium

Post by greenhorn666 »

indeed... :/
Post Reply