$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="ques"; // Table name
$con = mysql_connect("$host","$username")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$quesid=$_POST['quesID'];
$question =$_POST['questions'];
if ($quesid <> "")
{
$sql = "SELECT * FROM $tbl_name WHERE quesID = '$quesid'";
while($result= mysql_fetch_assoc($sql))
{
$quesi = $result['quesID'];
$ques = $result['ques'];
$op1 = $result['op1'];
$op2 = $result['op2'];
$op3 = $result['op3'];
$op4 = $result['op4'];
$exans = $result['exans'];
}
}
else
{
$sql = "SELECT * FROM $tbl_name WHERE questions='$question'";
while($result= mysql_fetch_assoc($sql))
{
$quesi = $result['quesID'];
$ques = $result['ques'];
$op1 = $result['op1'];
$op2 = $result['op2'];
$op3 = $result['op3'];
$op4 = $result['op4'];
$exans = $result['exans'];
}
}
?>
| Question ID : | " /> |
| Question : | " /> |
| Option 1 : | " /> |
| Option 2 : | " /> |
| Option 3 : | " /> |
| Option 4 : | " /> |
| Right Answer : | " /> |
Shubham SaxenaRank #278 · 8.9K reputationPosted Apr 4, 2014, 2:09 AM EDT
Shashank SrivastavaRank #1,097 · 1.7K reputationPosted Jul 1, 2014, 6:22 PM EDT
I can notice that the while loops that you have implemented are not of much use. What will be the use of going through every record when you are generating.the table out of the while scope. This will only result into printing the lasr record details. In order to print the form for every record, u need to place this form inside the while loop.
I hope this helps.
Shashank SrivastavaRank #1,097 · 1.7K reputationPosted Jul 1, 2014, 7:56 PM EDT
else $sql = "SELECT * FROM $tbl_name WHERE questions='$question'";
while($result= mysql_fetch_assoc($sql))
?>
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts