There is a database with an ID question and choiecs and one answer (multiple choice) I want to display it to all I will have a submit button at the end of the database with a checkbox on the left side and will check all the questions that I want to display under the table. My effort should be there is a more simple way! Thanks
$ result = mysqli_query ($ thief, "ID selection, question, choiceA, choiceB, choiceC, choiced, answer from q_and_a"); Echo "& lt; table border = '1' & gt; & lt; tr & gt; & lt; add & gt; add & lt; / or & gt; & lt; th & gt; # & lt; / th & Gt; & lt; th & gt; Questions & lt; / or & gt; & lt; th & gt; & lt; / th & gt; & lt; th & gt; B & lt; / th & gt; C & lt; / th & gt; & lt; th & gt; D & lt; / or & gt; & lt; th & gt; Answer & lt; / v & gt; & lt ; / Tr & gt; "; Echo '& lt; Form method = "POST" verb = "makeTest.php" & gt; '; While ($ line = mysqli_fetch_array ($ result)) {resonant "<<" Echo '& lt; Td> & Lt; Input type = "checkbox" name = "query []" value = "yes" & gt; & Lt; / Td> '; Echo "& lt; td & gt;" . $ Line ['id'] "& lt; / td & gt;"; Echo "& lt; td & gt;" . $ Line ['question'] "& lt; / td & gt;"; Echo "& lt; td & gt;" . $ Line ['choice'] "& lt; / td & gt;"; Echo "& lt; td & gt;" . $ Line ['option' B]] "& lt; / td & gt;"; Echo "& lt; td & gt;" . $ Line ['choice'] "& lt; / td & gt;"; Echo "& lt; td & gt;" . $ Line ['option'] "& lt; / td & gt;"; Echo "& lt; td & gt;" . $ Line ['answer'] "& lt; / td & gt;"; Echo "& lt; / tr & gt;"; } Resonates "& lt; / table & gt;"; ? & Gt;
I suggest throwing jQuery I'm mixed
Keep the HTML out of your PHP code and just ask it to the database.
Then use the AJAX / JSON DOM to update
update -. It has been tested (verified working), and some bugs were fixed by way of
<. P> ajax.php: & lt ;? Php $ action = $ _POST ["Action"]; If ($ action == "getquestions") {getchoestions () echo; } Function getQuestions () {{$ db = new PDF ("mysql: host = localhost; charset = utf8", "root", "root"); $ CMD = $ db- & gt; Prepare ("Selection ID, Question, Election A, Election B, Election C, Answer D, Answer with PL 2 questions;"); $ Cmd-> Executed (); $ Rows = array (); While ($ r = $ cmd- & gt; Fetch (PDO :: FETCH_ASSOC)) {$ rows [] = $ r; } $ Json = json_encode ($ rows); Return ($ json); } Hold (PDOException $ e) {echo $ e-> GetMessage (); Return; }}? & Gt;
questions.html
& lt; Html & gt; & Lt; Top & gt; & Lt; Script src = "// ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> & Lt; Script language = "javascript" & gt; Var questionsJson = ''; $ (Document) .ready (function () {getQuestions ();}); Function getQuestions () {$ .post ('ajax.php', {action: 'getQuestions'}, function (data) {questionsJson = data; displayQuestions ();} 'json'); } Function display question () {var colorAry = ['id', 'question', 'likes'', 'option' b, 'election' c '' 'option', 'answer']; (Var i = 0; i & lt; questionsJson.length; i ++) for {var q = questionsJson [i]; Top line = '& lt; TR & gt; & Lt; TD & gt; & Lt; Input type = "checkbox" name = "question []" value = "yes" & gt; & Lt; / TD & gt; '; For {var j = 0; j & lt; colAry.length; j ++} {row + = '& lt; Td> + Q [Callari [ja]] + '& lt; / Td> '; } $ ('# Main Table'). Append (line + '& lt; / tr & gt;'); }} & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Table ID = "Main Table" range = "1" & gt; & Lt; TR & gt; & Lt; Th & gt; Add & lt; / Th & gt; & Lt; Th & gt; # & Lt; / Th & gt; & Lt; Th & gt; Question & lt; / Th & gt; & Lt; Th & gt; & Lt; / Th & gt; & Lt; Th & gt; B & lt; / Th & gt; & Lt; Th & gt; C & lt; / Th & gt; & Lt; Th & gt; D & lt; / Th & gt; & Lt; Th & gt; Reply / Th & gt; & Lt; / TR & gt; & Lt; / Table & gt; & Lt; / Body & gt; & Lt; / Html & gt;
Comments
Post a Comment