thinkthrice Posted February 21, 2013 Share Posted February 21, 2013 Hello everyone, I am pretty new here on this site, I've been working on this for my school project about an online quiz exam...if you check my start.php file,its not sync..i was hoping when i press submit it goes to another question coming from the database but instead its properly ordered already, I know my work is way too complicated and not even near the finished product that i wanted thats why i wanted help here. So if possible i need assistance for some reason i cant upload my database here add1.php connection.php index.php new.css start.php view.php Quote Link to comment https://forums.phpfreaks.com/topic/274789-hello-there/ Share on other sites More sharing options...
exeTrix Posted February 21, 2013 Share Posted February 21, 2013 I think you're missing the point, we're not here to complete your work for you but assist as best we can with specific problems you may encounter. I don't mean to sound brash but I don't want to have to download a project, import a database etc etc and work out what should be done for you. Ask questions and we'll be happy to help. Quote Link to comment https://forums.phpfreaks.com/topic/274789-hello-there/#findComment-1413968 Share on other sites More sharing options...
thinkthrice Posted February 21, 2013 Author Share Posted February 21, 2013 I think you're missing the point, we're not here to complete your work for you but assist as best we can with specific problems you may encounter. I don't mean to sound brash but I don't want to have to download a project, import a database etc etc and work out what should be done for you. Ask questions and we'll be happy to help. I think you're missing the point, we're not here to complete your work for you but assist as best we can with specific problems you may encounter. I don't mean to sound brash but I don't want to have to download a project, import a database etc etc and work out what should be done for you. Ask questions and we'll be happy to help. ok sir i have this database which contains question i wanted to have a quiz where when i click proceed it goes to another question, as far as I've researched and done ive only managed to make the all the questions display there...the only problem i have now is to make the questions separated from each other Quote Link to comment https://forums.phpfreaks.com/topic/274789-hello-there/#findComment-1413970 Share on other sites More sharing options...
thinkthrice Posted February 21, 2013 Author Share Posted February 21, 2013 (edited) well this is the code im using <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body bgcolor="#330099"> <form id="formstart" name="formstart" method="GET" action="start2.php"> <?php //Include the connection details include ("connection.php"); //Create SQL query $query="select question,a,b,c,d from dummy"; //Execute the query $qr=mysqli_query($db,$query); if($qr==false){ echo ("Query cannot be executed!<br>"); echo ("SQL Error : ".mysqli_error($db)); } //Check the record effected, if no records, display a message if(mysqli_num_rows($qr)==0){ echo ("No record fetched...<br>"); }//end no record else{//there is/are record(s) while ($rekod=mysqli_fetch_array($qr)){//redo to next records echo $rekod['question']; echo '<input name="ans" type="radio" value="A" />' . $rekod['a']; echo '<input name="ans" type="radio" value="A" />' . $rekod['b']; echo '<input name="ans" type="radio" value="A" />' . $rekod['c']; echo '<input name="ans" type="radio" value="A" />' . $rekod['d'] . '<br>'; echo '<hr>'; } } ?> <input type="submit" name="submit" id="submit" value="SUBMIT"/> <?php ?> </form> </body> </html> Edited February 21, 2013 by thinkthrice Quote Link to comment https://forums.phpfreaks.com/topic/274789-hello-there/#findComment-1413971 Share on other sites More sharing options...
thinkthrice Posted February 21, 2013 Author Share Posted February 21, 2013 I'm really sorry about this, since i've only learnt HTML and not much CSS Quote Link to comment https://forums.phpfreaks.com/topic/274789-hello-there/#findComment-1413972 Share on other sites More sharing options...
Barand Posted February 21, 2013 Share Posted February 21, 2013 You could try something like this. Store the id of the current question as a session variable. When you query the table get the next question whose id is greater than the stored is. Display question and store the new id. <?php session_start(); if (!isset($_SESSION['qid'])) { $_SESSION['qid'] = 0; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body bgcolor="#330099"> <form id="formstart" name="formstart" method="GET" action="start2.php"> <?php //Include the connection details include ("connection.php"); //Create SQL query $query="SELECT id, question,a,b,c,d FROM dummy WHERE id > {$_SESSION['qid']} ORDER BY id LIMIT 1"; //Execute the query $qr=mysqli_query($db,$query); if($qr==false){ echo ("Query cannot be executed!<br>"); echo ("SQL Error : ".mysqli_error($db)); } //Check the record effected, if no records, display a message if(mysqli_num_rows($qr)==0){ echo ("No record fetched...<br>"); }//end no record else{//there is/are record(s) $rekod=mysqli_fetch_array($qr) ;//redo to next records echo $rekod['question']; echo '<input name="ans" type="radio" value="A" />' . $rekod['a']; echo '<input name="ans" type="radio" value="B" />' . $rekod['b']; echo '<input name="ans" type="radio" value="C" />' . $rekod['c']; echo '<input name="ans" type="radio" value="D" />' . $rekod['d'] . '<br>'; echo '<hr>'; $_SESSION['qid'] = $rekod['id']; } ?> <input type="submit" name="submit" id="submit" value="SUBMIT"/> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/274789-hello-there/#findComment-1413982 Share on other sites More sharing options...
thinkthrice Posted February 22, 2013 Author Share Posted February 22, 2013 You could try something like this. Store the id of the current question as a session variable. When you query the table get the next question whose id is greater than the stored is. Display question and store the new id. <?php session_start(); if (!isset($_SESSION['qid'])) { $_SESSION['qid'] = 0; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body bgcolor="#330099"> <form id="formstart" name="formstart" method="GET" action="start2.php"> <?php //Include the connection details include ("connection.php"); //Create SQL query $query="SELECT id, question,a,b,c,d FROM dummy WHERE id > {$_SESSION['qid']} ORDER BY id LIMIT 1"; //Execute the query $qr=mysqli_query($db,$query); if($qr==false){ echo ("Query cannot be executed!<br>"); echo ("SQL Error : ".mysqli_error($db)); } //Check the record effected, if no records, display a message if(mysqli_num_rows($qr)==0){ echo ("No record fetched...<br>"); }//end no record else{//there is/are record(s) $rekod=mysqli_fetch_array($qr) ;//redo to next records echo $rekod['question']; echo '<input name="ans" type="radio" value="A" />' . $rekod['a']; echo '<input name="ans" type="radio" value="B" />' . $rekod['b']; echo '<input name="ans" type="radio" value="C" />' . $rekod['c']; echo '<input name="ans" type="radio" value="D" />' . $rekod['d'] . '<br>'; echo '<hr>'; $_SESSION['qid'] = $rekod['id']; } ?> <input type="submit" name="submit" id="submit" value="SUBMIT"/> </form> </body> </html> You could try something like this. Store the id of the current question as a session variable. When you query the table get the next question whose id is greater than the stored is. Display question and store the new id. <?php session_start(); if (!isset($_SESSION['qid'])) { $_SESSION['qid'] = 0; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body bgcolor="#330099"> <form id="formstart" name="formstart" method="GET" action="start2.php"> <?php //Include the connection details include ("connection.php"); //Create SQL query $query="SELECT id, question,a,b,c,d FROM dummy WHERE id > {$_SESSION['qid']} ORDER BY id LIMIT 1"; //Execute the query $qr=mysqli_query($db,$query); if($qr==false){ echo ("Query cannot be executed!<br>"); echo ("SQL Error : ".mysqli_error($db)); } //Check the record effected, if no records, display a message if(mysqli_num_rows($qr)==0){ echo ("No record fetched...<br>"); }//end no record else{//there is/are record(s) $rekod=mysqli_fetch_array($qr) ;//redo to next records echo $rekod['question']; echo '<input name="ans" type="radio" value="A" />' . $rekod['a']; echo '<input name="ans" type="radio" value="B" />' . $rekod['b']; echo '<input name="ans" type="radio" value="C" />' . $rekod['c']; echo '<input name="ans" type="radio" value="D" />' . $rekod['d'] . '<br>'; echo '<hr>'; $_SESSION['qid'] = $rekod['id']; } ?> <input type="submit" name="submit" id="submit" value="SUBMIT"/> </form> </body> </html> thank you for your help sir,. but it still wont work, this statement is executed after i submit the answer if(mysqli_num_rows($qr)==0){ echo ("No record fetched...<br>"); } Quote Link to comment https://forums.phpfreaks.com/topic/274789-hello-there/#findComment-1414063 Share on other sites More sharing options...
thinkthrice Posted February 22, 2013 Author Share Posted February 22, 2013 You could try something like this. Store the id of the current question as a session variable. When you query the table get the next question whose id is greater than the stored is. Display question and store the new id. <?php session_start(); if (!isset($_SESSION['qid'])) { $_SESSION['qid'] = 0; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body bgcolor="#330099"> <form id="formstart" name="formstart" method="GET" action="start2.php"> <?php //Include the connection details include ("connection.php"); //Create SQL query $query="SELECT id, question,a,b,c,d FROM dummy WHERE id > {$_SESSION['qid']} ORDER BY id LIMIT 1"; //Execute the query $qr=mysqli_query($db,$query); if($qr==false){ echo ("Query cannot be executed!<br>"); echo ("SQL Error : ".mysqli_error($db)); } //Check the record effected, if no records, display a message if(mysqli_num_rows($qr)==0){ echo ("No record fetched...<br>"); }//end no record else{//there is/are record(s) $rekod=mysqli_fetch_array($qr) ;//redo to next records echo $rekod['question']; echo '<input name="ans" type="radio" value="A" />' . $rekod['a']; echo '<input name="ans" type="radio" value="B" />' . $rekod['b']; echo '<input name="ans" type="radio" value="C" />' . $rekod['c']; echo '<input name="ans" type="radio" value="D" />' . $rekod['d'] . '<br>'; echo '<hr>'; $_SESSION['qid'] = $rekod['id']; } ?> <input type="submit" name="submit" id="submit" value="SUBMIT"/> </form> </body> </html> You could try something like this. Store the id of the current question as a session variable. When you query the table get the next question whose id is greater than the stored is. Display question and store the new id. <?php session_start(); if (!isset($_SESSION['qid'])) { $_SESSION['qid'] = 0; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body bgcolor="#330099"> <form id="formstart" name="formstart" method="GET" action="start2.php"> <?php //Include the connection details include ("connection.php"); //Create SQL query $query="SELECT id, question,a,b,c,d FROM dummy WHERE id > {$_SESSION['qid']} ORDER BY id LIMIT 1"; //Execute the query $qr=mysqli_query($db,$query); if($qr==false){ echo ("Query cannot be executed!<br>"); echo ("SQL Error : ".mysqli_error($db)); } //Check the record effected, if no records, display a message if(mysqli_num_rows($qr)==0){ echo ("No record fetched...<br>"); }//end no record else{//there is/are record(s) $rekod=mysqli_fetch_array($qr) ;//redo to next records echo $rekod['question']; echo '<input name="ans" type="radio" value="A" />' . $rekod['a']; echo '<input name="ans" type="radio" value="B" />' . $rekod['b']; echo '<input name="ans" type="radio" value="C" />' . $rekod['c']; echo '<input name="ans" type="radio" value="D" />' . $rekod['d'] . '<br>'; echo '<hr>'; $_SESSION['qid'] = $rekod['id']; } ?> <input type="submit" name="submit" id="submit" value="SUBMIT"/> </form> </body> </html> and btw,where did "qid" came from is it constant? im not really that familiar and im willing to learn Quote Link to comment https://forums.phpfreaks.com/topic/274789-hello-there/#findComment-1414064 Share on other sites More sharing options...
thinkthrice Posted February 22, 2013 Author Share Posted February 22, 2013 I have managed to make it work,but it display the 3rd question...only the radio buttons,its only up to 2 stacks Quote Link to comment https://forums.phpfreaks.com/topic/274789-hello-there/#findComment-1414067 Share on other sites More sharing options...
Barand Posted February 22, 2013 Share Posted February 22, 2013 It worked when it left the factory. But, then again I'm not psychic and do not know your table structure. Adapt it. Quote Link to comment https://forums.phpfreaks.com/topic/274789-hello-there/#findComment-1414068 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.