arrow_upward

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Help]Php and Mysql
#4
ohk tried something.
for example here are a bunch of questions with there answers defined at question_list table by the admin/you at the db.
[Image: 4be6c15166.png]
here is he code:
PHP Code: (Select All)
$sql "SELECT * FROM question_list order by RAND() LIMIT 1";
$result $connect_db->query($sql);
$row $result->fetch_assoc();
$question $row['question'];
$answer $row['answer'];
echo 
"<b>Question: </b>".$question."<br><b>Answer: </b>".$answer

and here is the live review what the code does:
[Image: ae1f5b2ab5.gif]


And if you want do implement a checking type system then you can try this:
index.php:
PHP Code: (Select All)
include 'config.php';
$sql "SELECT * FROM question_list order by RAND() LIMIT 1";
$result $connect_db->query($sql);
$row $result->fetch_assoc();
$question $row['question'];
$answer $row['answer'];
if(
$row != null) {
echo 
"<b>Question: </b>".$question."<br>";
echo 
"<form method='POST' action='check.php'>
<input type='hidden' name='question' value='"
.$question."'/>
<input type='text' placeholder='Type Answer' name='answer'/>
<button type='submit'>SUBMIT</button>
</form>"
;
//echo "<b>Question: </b>".$question."<br><b>Answer: </b>".$answer;

here i have used config.php for logging the php file to the system..

and the check.php file can be like this:
PHP Code: (Select All)
include 'config.php';
$question $_POST['question'];
$sql "SELECT * FROM question_list WHERE question='$question'";
$result $connect_db->query($sql);
$row $result->fetch_assoc();
$question $row['question'];
$answer $row['answer'];
if(
$_POST['answer'] == $answer) {
    echo 
'Correct!';
} else {
    echo 
'Wrong!';

and here is its live demo:
[Image: 8f6c8c59b1.gif]

if you want config.php also then here it is:
PHP Code: (Select All)
$connect_db mysqli_connect("hostname here""username of account of mysql""accountt password""databasename");
if(!
$connect_db) {
    die(
"<b>Warning!</b> Connection Failed: ".mysqli_connect_error());

 Administrator
admin@post4vps.com


lockThread Closed 


Messages In This Thread
[Help]Php and Mysql - by jayant - 12-24-2016, 07:33 PM
RE: [Help]Php and Mysql - by Dynamo - 12-25-2016, 01:12 AM
RE: [Help]Php and Mysql - by jayant - 12-26-2016, 06:01 AM
RE: [Help]Php and Mysql - by Dynamo - 12-26-2016, 10:33 AM
RE: [Help]Php and Mysql - by jayant - 12-26-2016, 01:40 PM
RE: [Help]Php and Mysql - by Dynamo - 12-26-2016, 01:46 PM

Possibly Related Threads…
Thread
Author
Replies
Views
Last Post

person_pin_circle Users browsing this thread: 1 Guest(s)
Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - Hyper Expert - Shadow Hosting - Bladenode - Hostlease - RackNerd - ReadyDedis - Limitless Hosting