1

ユーザーが試験を作成するたびに、連続したアイテム番号を挿入したいと思います。彼が試験を作成するたびに、それは 1 に戻ります。皆さん、私はあなたの助けが非常に必要です。もっと力を。:)

ここに私のコードがあります:

$examid = $_SESSION['examid'];
$itemnum = 1;

$sql = mysql_query("INSERT INTO exam_questions (question_description, question_type, question_exam_id) VALUES ('$question', '$type', '$examid')")or die(mysql_error());
$lastinsertid = mysql_insert_id();
mysql_query("UPDATE exam_questions SET question_set_id='<??????????>' WHERE question_id='$lastinsertid' LIMIT 1")or die(mysql_error());
4

2 に答える 2

1

結合でこれを試してください:

UPDATE exam_questions eq cross join
       (select max(question_set_id) as qsi
        from exam_questions
        where question_id='$lastinsertid'
       ) as const
    SET eq.question_set_id = const.qsi + 1
    WHERE question_id='$lastinsertid';
于 2013-08-17T12:01:40.633 に答える