$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 : | " /> |
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Shashank SrivastavaPosted Jul 1, 2014, 11:56 PM
else $sql = "SELECT * FROM $tbl_name WHERE questions='$question'";
while($result= mysql_fetch_assoc($sql))
?>
Shashank SrivastavaPosted Jul 1, 2014, 10:22 PM
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.
Shubham SaxenaPosted Apr 4, 2014, 6:09 AM