Jump to content


Photo

Posting to MySQL, then getting the row number?


  • Please log in to reply
7 replies to this topic

#1 dagnasty

dagnasty
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 31 July 2006 - 07:26 PM

I'm making a poll system, but am confused by one thing.

Consider:
2 seperate polls can have the same poll name in the mysql database.

If after a user creates a poll, how do I go about getting the poll mysql id (auto incrementing) after the poll is created through a form. When post a new row the a mysql database, is there a way to find out it's location if it has auto incrementing id field?

For instance, if a user creates the poll and is taken to a "thanks for posting your poll. Here is a link to it"

#2 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 31 July 2006 - 07:28 PM

mysql_insert_id()
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#3 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 31 July 2006 - 07:29 PM

If you have an auto_increment field in the table and you want to know what the last value was set to, it's just mysql_insert_id(). You must have one and only one auto_increment column.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#4 dagnasty

dagnasty
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 31 July 2006 - 07:31 PM

What if multiple users are submitting simultaneously (not likely, but possible) would this be accurate?

#5 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 31 July 2006 - 07:34 PM

yes, it will be accurate.
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#6 dagnasty

dagnasty
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 31 July 2006 - 07:36 PM

Ahh i see it's put right after the query. I was thinking it called from the next page.

#7 dagnasty

dagnasty
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts

Posted 31 July 2006 - 07:36 PM

Thanks guys you're the best!

#8 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 31 July 2006 - 07:38 PM

Ahh i see it's put right after the query. I was thinking it called from the next page.

Yup. if you call it on the next page it might be another one. as long as you don't close the connection or perform another insert on the same page it will be the last id from the current connection.
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users