0

how can I get the row id of tbl_questions and send it to tbl_link_qa and then tbl_answers get to send it's row number to tbl_link_qa (same with tbl_questions) but this time it must correspond to the first row number from tbl_questions that was inserted first at tbl_link_qa

i need to link the row number of a question from tbl_questions and the row number of an answer from tbl_answers.

need help really bad

rec_id---qRec_id---aRec_id

96------------0-----------0

95------------0-----------0

I need to make it like this >>

rec_id---qRec_id----aRec_id

96----------123----------456

95----------124----------

123 and 124 is the row number from tbl_questions inserted into tbl_link_qa and 456 is from tbl_answers

4
  • Some database fields/tables/queries and code you have tried would help Commented Feb 9, 2011 at 14:04
  • no it's not homework, more like my thesis T_T Commented Feb 9, 2011 at 14:07
  • One period, no capitalization. Effort in, effort out. Commented Feb 9, 2011 at 14:23
  • You have written your question like an IM to a teenager: no capitalization, huge run-on sentences, no formatting. Andrew would like you to put more effort into asking your question if you want others to put effort into providing you with free work. Commented Feb 9, 2011 at 14:31

1 Answer 1

1

Use mysql_insert_id to get the auto_increment ID of the last row you inserted.

Ex:

mysql_query("INSERT INTO tbl_questions VALUES (something)");
$question_id = mysql_insert_id();

mysql_query("INSERT INTO tbl_answer VALUES (something)");
$answer_id = mysql_insert_id();

mysql_query("INSERT INTO tbl_link_qa (qRec_id, aRec_id) VALUES ($question_id, $answer_id)");
Sign up to request clarification or add additional context in comments.

10 Comments

it's not exactly the last row inserted but more like the first row inserted.
"Last" means "most recent", as in "this is the identifier generated for the INSERT query you most recently ran on this connection". I have saved the ID of the row inserted into each table, what more are you asking for?
rec_id qRec_id aRec_id 96 0 0 95 0 0 this is what my tbl_link_qa looks like now, qRec_id comes from tbl_questions wherein it's the row number of the question submitted and aRec_id is the row number of the answer from tbl_answers.
My code gives you the ID of the row from tbl_questions and the ID of the row from tbl_answers... Then it puts them into your link table... Is there a reason you shared this schema with me? Was "question_id" instead of "qRec_id" confusing?
I guess so, I'm really pretty new in php. I'm not used to coding, I mostly and only do the designs since I do graphics so this is really a big challenge for me
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.