Jump to content

Archived

This topic is now archived and is closed to further replies.

DarkReaper

Mysql help with forming insert/select

Recommended Posts

Okay here is what i have in theory:
A list of users.
1. If a user clicks on another users name mysql inserts a row in the db saying that the users requests lets say "chat".
2. set a session var to the row id for the 1-st user.
3. The second users sees that its attention is requested and clicks on the above users name, mysql update-s the row acccoudingly.
4. set a session var to the row id for the 2-nd user
5. Both users do their "chat".

So far so good. But if both users click at the same time 2 rows get inserted (sometimes), usually the 2 sessions vars should be the same but they are not since mysql inserted 2 rows and the 2 vars are different, and the whole module gets to hell cous one user thinks it is "chatting" with someone as is the other, but in fact noone cant see the other couse the 2 rows in the db kinda kill functionallity.

In short 2 rows exist but there should be only 1.

Dont know if you understood me ...

*notice: i say "chat" because i cant think of a word to fully classify it.

Share this post


Link to post
Share on other sites
Well, short of locking the tables, it sounds you need to search for any existing pairings before you insert a fresh one.

Share this post


Link to post
Share on other sites
I do it. Before each insertion i check if a row doesnt already exist ... and if doesnt exist insert it. But if they click at the same time 2 rows get inserted.

Share this post


Link to post
Share on other sites
Then you'll have to lock the tables, or come up with some sort of unique key restrictions.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.