开发者

Need to Insert then update a field in a table

开发者 https://www.devze.com 2023-02-09 21:13 出处:网络
Need help badly guys, I have three tables tbl_questions, tbl_answers and tbl_link_qa tbl_questions is where the questions from students get stored and tbl_answers is where the experts answer should

Need help badly guys,

I have three tables tbl_questions, tbl_answers and tbl_link_qa

tbl_questions is where the questions from students get stored and tbl_answers is where the experts answer should be stored. tbl_link_qa connects the two tables in which the id number from tbl_questions gets stored in tbl_link_qa as q_std_id same idea with the id number from tbl_answers only that instead of insert, it updates if it finds an id number in tbl_link_qa without and expert id

i know this sounds confusing but I really need your help guys, I'm having my defense next week and I NEED to get this

here's my code:

i had to remove my update code since it was clearly not working T_T

$exp_reply = $_REQUEST['expertAnswerTypeBox'];  
$idnumber = $_REQUEST['exp_id'];
$std_question = $_REQUEST['question'];

$q_id = $_REQUEST['std_开发者_运维知识库id'];


$sql2="SELECT * FROM tbl_teacher WHERE exp_id='$idnumber'";
$call_exp = "SELECT * FROM tbl_teacher WHERE exp_id='$idnumber'";

$call_std = "SELECT * FROM tbl_link_qa WHERE q_std_id='$q_id'";

$sql3="SELECT * FROM tbl_questions WHERE question ='$std_quesion'";     
$results = "Insert into tbl_answers(answers,id_exp) values('$exp_reply','$idnumber')";
$insert_a_link = "Insert into tbl_link_qa(a_exp_id) values($idnumber)";


Add an index unique in your tbl_link_qa on field that you use to store question id. Replace the last line to:

$insert_a_link = "REPLACE into tbl_link_qa(a_exp_id) values($idnumber)";

If the question already present in tbl_link_qa the row will be replaced by the new, if the question not present in tbl_link_qa the insert works normaly. This is what you want?

0

精彩评论

暂无评论...
验证码 换一张
取 消