Nested loops in php mysql -
i cant update corresponding edited items. first questions , answers being updated. cant result want. im stuck on day. please me.
heres scenario: have php file contains form , passes php file. checkbox has question id , textboxes allows them edit questions database. every question has corresponding answers. also, can edit them. if click update button of checked questions should updated. not of them updated. literally first question item can updated. knows whats wrong code??
heres link screenshot http://imageshack.us/photo/my-images/706/cetw.png/
heres code:
$selected = $_post['selected'];///the checkbox $question = $_post['questiondesc']; ($i = 0; $i < sizeof($selected); $i++) { $sql = sprintf("update exam_questions set question_description = '%s' question_id = '%s'", mysql_real_escape_string($question[$i]), mysql_real_escape_string($selected[$i])); mysql_query($sql)or die(mysql_error()); $eren = mysql_query("select * exam_answers answer_question_set_id = '".$selected[$i]."'")or die(mysql_error()); while($mikasa = mysql_fetch_array($eren)){} $count = mysql_num_rows($eren); $answer = $_post['answerdesc']; $answerid = $_post['ansid'];///answer id for($e = 0; $e<$count; $e++){ $gomugomu = sprintf("update exam_answers set answer_description = '%s' answer_id = '%s'", mysql_real_escape_string($answer[$e]), mysql_real_escape_string($answerid[$e])); mysql_query($gomugomu)or die(mysql_error()); }
it's little confusing understand without printscreen of page or something, sounds have page allows multiple checkboxes selected @ same time, yet you're keeping reference single checbox in $_post
.
if that's case, should sending questions' id's through array. please take @ accepted answer see how can done: php $_post data array
Comments
Post a Comment