php


How to search everything except something


I have 3 tables in the database.
1st table (news) of "All news released" with columns
NEWS_ID
2nd table (plyrs_read) of "players who read the news and which news" with columns
PLAYER_ID | NEWS_ID
3rd table (players) with of "All players on server". with columns
PLAYER_ID
I want to show a player all the news which the player hasn`t read. I have his id in $id.
Now I need help to get all those NEWS_ID in an array
How about this?
SQLFIDDLE DEMO
select * from news n
where id not in(select pn.nid
from player_news pn
where pn.pid = 1)
;
Results:
| ID | TITLE |
----------------
| 1 | country |
SELECT *
FROM news
WHERE news_id NOT IN(SELECT r.news_ID
FROM plyrs_read r
INNER JOIN players p ON r.Player_ID = p.Player_ID
WHERE p.player_ID = 'some id'
AND r.news_ID IS NOT NULL);
SQL Fiddle Demo
SELECT NEWS_ID FROM table1
WHERE NEWS_ID NOT IN
( SELECT NEWS_ID FROM table2 WHERE PLAYER_ID = $id )
SELECT n.NEWS_ID FROM news n
LEFT OUTER JOIN plyrs_read pr
ON n.NEWS_ID = pr.NEWS_ID AND pr.PLAYER_ID = $id
WHERE pr.NEWS_ID IS NULL

Related Links

mPDF: how to remove setHeader() & setFooter() borders
Display number of item in the cart if %d > 0 else display %d
not getting paypal transaction id in return url while paying to buyers account
Mysql: Select Count And IN Clause in One Query
Calling model function in blade brake view - Laravel
MySQL PHP sign up form username check [duplicate]
ODM, Symfony: translations and forms
Form HTML and PHP [duplicate]
Looping prepared statments
PayPal IPN: how to respond with invalid notification
Sending AJAX-Request to MySQL and getting JSON back via php/jQuery
How to filter out sections of an array with subsections in PHP?
SimplePie on PHP not skipping bad feeds
Is there a way to make my website automatically scan database and do pre determined functions?
No method is configured to handle the multipart config key - Laravel 5.4 using mailgun
Exiting in custom session handler

Categories

HOME
generics
automapper
angular-ui-grid
postgresql-9.4
celery
twitter-fabric
biztalk-2010
linker
capistrano
amazon-emr
jquery-select2-4
grocery-crud
spring-jpa
amazon-elb
fresco
asciimath
mixpanel
boomi
xsl-fo
multiple-tables
pst
cellular-network
offline-caching
sap-lumira
sendmessage
tsung
basic-authentication
actframework
plantuml
markov-chains
gnu-classpath
adminer
directfb
express-session
stackpanel
eclipse-gmf
llvm-ir
hypothesis-test
robust
apache-toree
phppgadmin
gestures
sonatype
sequence-diagram
popen
predicates
rustdoc
elastic4s
thread-exceptions
xmlbeans
pyaudio
tsqlt
traversable
fragmentstatepageradapter
gnucash
codecharge
mathnet
jeditable
persistent-object-store
seadragon
wif4.5
voronoi
ioexception
ibm-was
highest
android-studio-import
extend
rfc5545
hp-idol-ondemand
vs-unit-testing-framework
storing-data
armv6
frontbase
iirf
notifyjs
tnt4j
jacob
notin
ntlmv2
xcode4.5
wndproc
chronometer
uitextfielddelegate
series-40
datacontracts
nsconnection
bll
android-2.1-eclair
jdownloader
ppc
firephp
downcasting
tso
watchpoint
chronic

Resources

Encrypt Message