Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8609791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:57:58+00:00 2026-06-12T03:57:58+00:00

Im gonna try to explain what I need to do. I have a table

  • 0

Im gonna try to explain what I need to do.

I have a table and in that table I have ID. This ID is my primary key (auto_increment).
And I have a second table.

What I need is when I save something in my seconds table I want to use the ID of my first table.

I have read much things but I only got more headache from it so if anyone could help me with this I would be gratefull.

Rgrds

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:58:00+00:00Added an answer on June 12, 2026 at 3:58 am

    You need the concept of a foreign key. This can be defined as a constraint or just used as such. Let’s assume you have “Teachers” and “Pupils” and pupils are assigned to one teacher. So the teacher has an ID. Now your “Pupils” table has an ID as well (it’s primary key) and a foreign key TEACHER_ID, which refers to the teacher entry.

    ALTER TABLE `Pupils` ADD FOREIGN KEY (TEACHER_ID) REFERENCES `Teachers` (ID)
    

    will create a constraint, that TEACHER_ID refers to the ID of a Teacher.

    In PHP if you create both entries at once. You can first insert the teacher and then use:

    $teacherID = mysql_insert_id();
    

    which will return you the last auto_increment value (in this case your teachers ID) and then set this as the TEACHER_ID for your pupils entry.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first I'm gonna try to explain what exactly I want to do: I have
Ok guys I'm gonna do my best to explain this. I have a list
I'm gonna try and simplify this as much as possible. Lets say i have
$('input#not-gonna-work').bind({ keyup: function(){ console.log('Typed a key'); $(this).val($(this).val() + '.');// try with any other char
I'm gonna try to reword this more properly as the last two questions pertaining
I'm gonna try to explain at my best. I use Play Framework 2, and
I'm gonna try to explain my problem : I'd like to allow users to
Hello sorry if this may be a stupid question, I am gonna try a
This is gonna take some explaining but here it goes. I need to author
Hey, I'm AI Student and gonna try my homework that is implementation of A*

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.