/    Sign up×
Community /Pin to ProfileBookmark

Problem with a query …

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.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@JonaNov 26.2003 — [font=arial]"Not equal to" is <> in MySQL, not !=[/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@turbauthorNov 26.2003 — != work in query and for my problem, i finally found an answer, don't know if it's the best but it work :

[code=php]
$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);

[/code]
Copy linkTweet thisAlerts:
@JonaNov 26.2003 — [i]Originally posted by pyro [/i]

[B]Actually, it's both: http://www.mysql.com/doc/en/Comparison_Operators.html [/B][/QUOTE]


[font=arial]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: [/font]

[b][J]ona[/b]
Copy linkTweet thisAlerts:
@pyroNov 26.2003 — lol... I hear you. The MySQL documentation could use some work.
×

Success!

Help @turb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...