I ask this with limited SQL understanding, apologies in advance if it’s obvious. I have a select query that returns a result set of ‘unread’ messages and matches the sender ID from a table of users (called authors) for a simple web application I am working on. The tables are described below:
Authors:
aId int(20) NO PRI NULL auto_increment
aUser varchar(30) NO UNI NULL
aPass varchar(40) NO NULL
aEmail varchar(30) NO UNI NULL
aBio mediumtext YES NULL
aReg datetime NO NULL
Messages:
msgId int(20) NO PRI NULL auto_increment
mSender int(20) NO MUL NULL
mReciever int(20) NO MUL NULL
mTitle tinytext NO NULL
mBody mediumtext NO NULL
mRead tinyint(4) NO NULL
mDate datetime NO NULL
The select query is I am using is (Tks martina):
SELECT messages.mTitle, messages.mBody, messages.mDate, authors.aUser
FROM messages LEFT JOIN authors on aId=mSender WHERE mReciever = '$aId' AND mRead = '0'
$aId is a php session variable that contains the userID of the active user. My php application will assume since this ‘unread’ message has been processed it is now read, could anyone assist with modification of the above query to also update mRead to 1, indicating it is read, from an existing post on here i read you can't SELECT with UPDATE in the same SQL statement, would there be another way around this, am i miles away from the correct solution?.any help much appreciated. Many thanks in advance.