Tjk Posted May 20, 2006 Share Posted May 20, 2006 I'm having some trouble coming up with a method of doing this...Run a mysql query and select userids from one table. I then don't want these userids to be selected/displayed in the second query I run in a different table.[code]$query= mysql_query("SELECT * from friends WHERE friend1='$userid'") or die(mysql_error());while($row= mysql_fetch_assoc($query)){echo $row['userid'];}//some more code// this query should not display the userids from displayed in the query above$query= mysql_query("SELECT * from information WHERE userid='$userid'") or die(mysql_error());while($row= mysql_fetch_assoc($query)){echo $row['userid']; }[/code]I was wondering if I could create an array of the userids selected from the 1st query and then tell the mysql to exclude them in the second query but I wasn't sure if this was possible.Any ideas on how I can do this?Regards,-Tjk Quote Link to comment https://forums.phpfreaks.com/topic/10061-array-for-excluding-values/ Share on other sites More sharing options...
toplay Posted May 20, 2006 Share Posted May 20, 2006 It can be done with one query. Try the SQL below and that should work if I understand you correctly. It will display all the rows in the "information" table that don't match one in the "friends" table.[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] *[color=green]FROM[/color] [color=orange]`information`[/color] [color=green]LEFT[/color] [color=green]JOIN[/color] `friends` ON `information`.userid [color=orange]=[/color] `friends`.friend1[color=green]WHERE[/color] `friends`.friend1 IS NULL [!--sql2--][/div][!--sql3--]Example:If the "information" table had these rows of userid's:12345And the "friends" table had these rows of friend1's:123The SQL would select and display just:45 FYI:Join tutorial:[a href=\"http://www.keithjbrown.co.uk/vworks/mysql/mysql_p5.shtml\" target=\"_blank\"]http://www.keithjbrown.co.uk/vworks/mysql/mysql_p5.shtml[/a] Quote Link to comment https://forums.phpfreaks.com/topic/10061-array-for-excluding-values/#findComment-37428 Share on other sites More sharing options...
Tjk Posted May 21, 2006 Author Share Posted May 21, 2006 EDIT: Thanks for all your help. I had play around with it a bit but I understand it and have been able to get it to work.Regards,-Tjk Quote Link to comment https://forums.phpfreaks.com/topic/10061-array-for-excluding-values/#findComment-37675 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.