mysqli - How to display a set of queston using while loop in php -
I have 10 options like their options in the database: ID question option1 option2 option3
Code that randomly selects 1 question and displays it on the webpage with its options. Now I want to have five random questions displayed on each webpage with their respective options. How can I do this, please help me
& lt ;? Php include_once ("db_conx.php"); $ Sql = "SELECT * mymake ORDER BY RAND ()"; $ Query = mysqli_query ($ db_conx, $ sql); $ Numrows = mysqli_num_rows ($ query); If ($ numrows> 0) {while ($ row = mysqli_fetch_array ($ query, MYSQLI_ASSOC)) {$ id = $ row ["id"]; $ Question = $ line ["question"]; $ Option1 = $ line ["option1"]; $ Option2 = $ line ["option2"]; $ Option3 = $ line ["option3"]; }}? & Gt; & Lt ;; Doctype html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Meta charset = "UTF-8" & gt; & Lt; Title & gt; Untitled document & lt; / Title & gt; & Lt; Style & gt; .ask {float: left; Height: auto; Width: 100%; Margin-top: 10px; } Input {background: transparent; } Option {color: # C03; } Placeholder {color: # C03;} & lt; / Style & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div class = "ask" & gt; & Lt; Form & gt; & Lt; Input type = "text" name = "q1" placeholder = " size =" 82 "> gt; & gt; gt selection &; & lt; option value =" & lt ;; Php echo $ option1 ;? & Gt; "& gt; & lt ;? php echo $ option1;? & Gt; & lt; / option & gt; & lt; option value =" & lt ;? Php echo $ option2 ;? & Gt; "& gt; & lt ;? php echo $ option2;? & Gt; & lt; / option & gt; & lt; option value =" & lt ;? Php echo $ option3 ;? & Gt; "& gt; & lt ;? php echo $ option3;? & Gt; & lt; / option & gt; & lt; / select & gt; & lt; / form & gt; & lt; / div & Gt; & lt; / body & gt; & lt; / html & gt;
thanksgiving
So your current code is actually a thief through all of your queries in your database, every time you reassign your questions and options, when it goes through them. At the last minute, they use those variables to form a form.
In your loop you $ options
, etc. ARA and then loop through them in their code 5 times.
The code has made quick changes, but instead of specifying its variable, HTML code is output.
0) {while ($ row = mysqli_fetch_array ($ query, MYSQLI_ASSOC)) {? & Gt; & Lt; Input type = "text" name = "q <" php echo $ line ["id"];? & Gt; " Placeholder = "& lt ;? php echo $ line [" question "] ;? gt; Size = "82" & gt; & Lt; Gt selection and; & Lt; Option value = "& lt ;? php echo $ row [" option1 "] ;? & gt;" & Gt; & Lt ;? Php echo $ line ["option1"]; ? & Gt; & Lt; / Options & gt; & Lt; Option value = "& lt ;? php echo $ row [" option2 "];? & Gt;" & Gt; & Lt ;? Php echo $ line ["option2"]; ? & Gt; & Lt; / Options & gt; & Lt; Option value = "& lt ;? php echo $ row [" option3 "] ;? Gt;" & Gt; & Lt ;? Php echo $ line ["option3"]; ? & Gt; & Lt; / Options & gt; & Lt; / Select & gt; & Lt ;? Php}}? & Gt; & Lt; / Form & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;
Hope this takes you to the right path.
Comments
Post a Comment