views:

59

answers:

2

EDIT: changed the whole question sorry, im trying to deal with the mysql DATETIME values, this is my mysql query:

$result="SELECT u.username, u.picture, m.id, m.user_note, m.reply_id, m.reply_name, m. m.dt
FROM relationships r, notes m, user u
WHERE m.user_id = r.leader
AND r.leader = u.user_id
AND r.listener ='".$_SESSION['user_id']."'
UNION
SELECT username, picture, id, user_note, reply_id, reply_name, dt
FROM user u, notes b
WHERE u.user_id = b.user_id
AND b.user_id = '".$_SESSION['user_id']."'
AND dt < '".$lastmsg."'
ORDER BY dt DESC
LIMIT 10 ";

im trying to find rows from this query older than '$lastmsg' and not $lastmsg itself, i thought about using less than but not equal to operator! im not sure if that was stupid!!!

P.S the query works, but its retriving wrong information!!

A: 

Shouldn't the query fragment that looks at the date be

AND dt > '".$lastmsg."'

?

Pointy
the data is retrived and shown, my first default post is shown again when i click MORE!
getaway
Isn't the first post always returned by the query? It's really not at all clear what you're trying to do. Keep in mind that we don't know what your schema means.
Pointy
its exactly like twitter, when you load more updates, you can expect to see the same status message again when you click more!!
getaway
And my point is that you're not correctly interpolating the value of "$lastmsg" into the query - you're passing the string "$lastmsg" instead of the value of the variable.
Pointy
i changed what you told me to do! but it still giving me the same duplicate!! it deos not make a difference, thanks for trying
getaway
i think something is wrong with my schema, im going to change my whole question!
getaway
A: 

You are only restricting the date on the second half of your UNION. Try this instead:

SELECT u.username, u.picture, m.id, m.user_note, m.reply_id, m.reply_name, m.dt
FROM relationships r, notes m, user u
WHERE m.user_id = r.leader
AND r.leader = u.user_id
AND r.listener ='".$_SESSION['user_id']."'
AND m.dt < '".$lastmsg."'
UNION 
SELECT username, picture, id, user_note, reply_id, reply_name, dt
FROM user u, notes b
WHERE u.user_id = b.user_id
AND b.user_id = '".$_SESSION['user_id']."'
AND dt < '".$lastmsg."'
ORDER BY dt DESC
LIMIT 10
RickF
thanks, but its still pulling out the same data
getaway
Can you run the query directly to confirm that the problem is in the query? You might want to try running them separately as well to see which part of the UNION is returning the unwanted row.
RickF
yeh thats what im going to try now? :)
getaway
i dnt know whats wrong this is killing me, thers something not logical
getaway
What did the testing turn up?
RickF
its the first query that bring out the unwanted result!!
getaway
Problem resolved?
RickF
If "dt" is a timestamp, and you're trying to get *newer* messages, shouldn't you be looking for rows where "dt" is *greater* than the last timestamp limit? Time values get bigger as we move into the future. Unless you're Merlin.
Pointy
I'm pretty sure he's working blog-style: newest entries are loaded, hit -more- for older stuff.
RickF