Click to See Complete Forum and Search --> : Problem with a query ...


turb
11-25-2003, 05:31 PM
Hi!

Here's the situation: I've got 2 tables (gang and profil).

I've need to create some group of member (ex. member from Australia). When i check the page that display a group info (like # of member, the member code, ...) i what to be able to add or remove member. So to do this, i've create 2 formlist and all works well. In the first one, i've got the member for a specific group and in the second one, i've got all member.

My problem is that i can't figure out how i can display just the member that are already not in this group:

$sql = "SELECT * FROM gang AS g, profil AS p WHERE g.Group = "a specific group" AND ... ????

I try this:

$sql = "SELECT * FROM gang AS g, profil AS p WHERE p.Type = '".$type."' AND g.Gang = '".$group."' AND g.Code != p.Code ORDER BY p.Code ASC";

but here's the problem:

if the group contain 3 members (m01, m02, m03) and i've got 3 members in total, in therory, i'm suppose to got an empty list but here's what i get:

m01
m01
m02
m02
m03
m03

i understand what cause this but don't know how to fix it.

Jona
11-25-2003, 08:13 PM
"Not equal to" is <> in MySQL, not !=

[J]ona

pyro
11-25-2003, 08:16 PM
Actually, it's both: http://www.mysql.com/doc/en/Comparison_Operators.html

turb
11-25-2003, 08:34 PM
!= work in query and for my problem, i finally found an answer, don't know if it's the best but it work :


$sqlA = "SELECT * FROM gang WHERE Gang = '".$group."' ORDER BY Code ASC";
$sqlB = "SELECT * FROM profil WHERE Type = '".$type."' ORDER BY Code ASC";

$resultA = mysql_query($sqlA) or die('Erreur : '.mysql_error());
$resultB = mysql_query($sqlB) or die('Erreur : '.mysql_error());

//Generate In-User Array
$i = 0;
$in = array();
while ($rowA = mysql_fetch_array($resultA)){
$in[$i] = $rowA["Code"];
$i++;
}

//Generate All-User Array
$i = 0;
$all = array();
while ($rowB = mysql_fetch_array($resultB)){
$all[$i] = $rowB["Code"];
$i++;
}

//Generate Out-User Array
$out = array_diff($all, $in);

Jona
11-25-2003, 08:45 PM
Originally posted by pyro
Actually, it's both: http://www.mysql.com/doc/en/Comparison_Operators.html

PHP.net's documentation is a lot easier to find information in... Took me forever just to find out <> was "not equal to." Gee... Sorry about that, then. :rolleyes:

[J]ona

pyro
11-25-2003, 08:53 PM
lol... I hear you. The MySQL documentation could use some work.