Jump to content

help with php quiz


Karlaugustsson90

Recommended Posts

hello everyone im reativlivly new to php and mysql and i am in desperate need of any kind of help right now.

i am building a quiz with multiple answers, and i have spent sleepless nights trying to figure out how to display my mysql data in php.

 

i want all my questions with their answers to displayed something like:

 

Name of quiz

 

question 1 ___________

 

answer a [] | picture  |

answer b []

answer c [] |          |

____________

question 2 ___________

 

answer a [] | picture  |

answer b []

answer c [] |          |

____________

question 3 ___________

 

answer a [] | picture  |

answer b []

answer c [] |          |

____________

 

:Submit:

 

Here are dumps from my database

 

Dumping data for table quiz

quiz_id quiz_name datecreated         pdf

32 multiplikation 2011-02-02 19:07:29 multiplikation

 

Dumping data for table question

quiz_id questionary question_id img

32 vad blir fem plus 7 2 vad_blir_fem_plus_7

32 vad blir 4 gånger 7 31 vad_blir_4_gånger_7

 

 

Dumping data for table answer

answer_id quiz_id question_id answerr truefalse

117           32   2           12   1

118           32   2           13   0

119           32   2           67   0

120           32   2           77   0

121           32   31           76   1

122           32   31           55   0

123           32   31           28   0

124           32   31           44   0

 

As you can see each table share the same quiz_id, the answer table gets the question_id from the table  question.

 

and here is my php code (please take note that i'm a newbie in both php and mysql)

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<?php

require_once ("include/connect.php");

?>

 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<link href="style.css" rel="stylesheet" type="text/css" />

</head>

 

<body>

<div class="box">

<div class="box2">bajs</div>

<div class="box3">

 

<?php

$get=$_POST['quiz'];

 

//visa quizens namn

$query2="SELECT * FROM quiz WHERE quiz.quiz_id=$get";

$result2= mysql_query($query2)or die (mysql_error());

//RUN THROUGH

while($row2=mysql_fetch_array($result2)){

 

echo"<p>";

echo $row2['quiz_name'];

echo"</p>";

}

?>

 

<?php

 

//visa quizens namn

$query3="SELECT * FROM question,answer WHERE question.quiz_id=$get AND question.question_id=answer.question_id GROUP BY answer.question_id";

$result3= mysql_query($query3)or die (mysql_error());

//RUN THROUGH

while($row3=mysql_fetch_array($result3)){

echo"<p>";

echo $row3['questionary'];

 

echo"</p>";

echo"<p>";

echo $row3['answerr'];

 

echo"</p>";

}

 

?>

 

</div>

 

 

</div>

</body>

</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.