dpzbzp8728 2011-02-08 18:34
浏览 22
已采纳

需要插入然后更新表中的字段

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)";
  • 写回答

1条回答 默认 最新

  • duanchan9354 2011-02-08 18:52
    关注

    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?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度