Jump to content


Photo

Mysql help with forming insert/select


  • Please log in to reply
3 replies to this topic

#1 DarkReaper

DarkReaper
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 07 August 2006 - 07:10 PM

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.

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 07 August 2006 - 10:56 PM

Well, short of locking the tables, it sounds you need to search for any existing pairings before you insert a fresh one.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 DarkReaper

DarkReaper
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 08 August 2006 - 01:32 PM

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.

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 08 August 2006 - 02:31 PM

Then you'll have to lock the tables, or come up with some sort of unique key restrictions.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users