Last one, I think... PHP/MYSQL Related..

Discussion in 'OT Technology' started by venger240, Nov 3, 2005.

  1. venger240

    venger240 Hoemoe

    Joined:
    Oct 20, 2003
    Messages:
    2,938
    Likes Received:
    0
    Location:
    Nashville, TN
    Hey guys, I have just about got everything working. The last thing I need to do is connect two databases via one unique number...

    The first database is setup with all the information we want to keep forever(name, date, score, case type, manager) and then the second database holds the results of the audit scores, but will only hold them for 3 months.

    So I have a form setup with all the questions. When the form is submitted the score is added together, and then put into the main database. Each record in the main database has an id, which is auto increment. How do I get that auto incremented number into the id field of the second database at the same time as the answers to the questions?? Any clues? Thanks.
     
  2. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    The data is going into both databases at the same time, correct? So put the data into the forever table, pull the ID back out, put the data into the other database. Or am I missing something? :dunno:
     
  3. venger240

    venger240 Hoemoe

    Joined:
    Oct 20, 2003
    Messages:
    2,938
    Likes Received:
    0
    Location:
    Nashville, TN

    Thats exactly what I want to do, but im not sure how to do it, since the id field is an auto incrementing number. How would I retrieve that?
     
  4. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    After you put the record in the database, just select the ID from that record.

    SELECT id FROM table WHERE blah = 'blah' AND whatever = 'something' ...;

    Assuming, of course, that you can uniquely identify the record by the combination of all the attributes other than the ID.

    Alternately, you could generate the ID yourself.
     
  5. venger240

    venger240 Hoemoe

    Joined:
    Oct 20, 2003
    Messages:
    2,938
    Likes Received:
    0
    Location:
    Nashville, TN

    Thats my problem.. There is no way of uniquely identifying the record other then the id number being made in the database. I really have no clue how else I could go about generating the ID number myself...

    Is there a way to pull the newest record entered into the database?
     
  6. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    You could generate the ID yourself by grabbing the biggest ID that's currently in the database (SELECT MAX(id) FROM table), then incrementing it by 1. You know it'll be unique since there's nothing bigger than the max already in the database.
     
  7. venger240

    venger240 Hoemoe

    Joined:
    Oct 20, 2003
    Messages:
    2,938
    Likes Received:
    0
    Location:
    Nashville, TN
    Then couldnt I just do that to select the id? Since its auto incrementing, everytime a new record is made, it will be the highest number. Hmm, I will have to try this, thanks for that.
     
  8. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Yeah, that would probably work. By generating it yourself, however, you can be sure that you have the right one (I'm not entirely sure how MySQL generates new ID's - they may not be just incremented).
     
  9. venger240

    venger240 Hoemoe

    Joined:
    Oct 20, 2003
    Messages:
    2,938
    Likes Received:
    0
    Location:
    Nashville, TN
    MAX() worked perfectly. Thanks again! :)
     

Share This Page