how to display only 3 different questions everyday from database? – PHP

  php

Q(Question):

i want to display questions and multiple answers from database. this code will display all the questions from the database. i want to display only 3 questions daily. every day new set of question should be displayed… how to do it?

Test.php


<?php
include("config.php");
session_start();
include("lock.php");
?>
<?php
echo "<form method='post' id='submit' action='checkresult.php'>";
$sql="SELECT * FROM cquestions";
$result=mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "<p>" . $row['cqtext'] . "</p>";
$sql2="SELECT * FROM canswers where cqid=".$row['cqid'];
$result2=mysql_query($sql2);
while($row2=mysql_fetch_assoc($result2)){
echo "<input type='radio' name='".$row['cqid'].
"' value='".$row2['ccans']."' />".$row2['aatext'];
}
/*echo "<input type='hidden' name='email' value='email' />";*/
}
echo"<input type='submit' id='submit' name='submit' value='Submit Answers'/>";
echo "</form>";
?>

A(Answer):


SELECT rand(), c.*
from cquestions as c
order by 1
limit 3,

This will display only 3 rows (‘limit 3’) with the smallest random number (‘rand()’)

A(Answer):

You will need to keep track of those that you already displayed by using a flag or counter of some sort and either filter those flagged out or sort by the counter.

A(Answer):

okay. but it will display random questions every time the page loads.i want do display 3 questions one full day. only the next day the questions should change.

A(Answer):

Yes, take Luuk’s SQL and implement my modification and you will get what you want.

A(Answer):

You will also have to give a definition to ‘one full day’.
The internet is something world-wide.

Where i am living it’s now 22:09, so in 2 hours another day will start… But, will this also be a fact for all your visitors?

(My local timezone is CEST, or +02:00)

A(Answer):

Yes, Luuk is right. Either you assume your web-server’s time to consider a day or correct it for your local time zone.

Now that depends on your requirement, if the web-server’s date/time is more suitable to you and if you have saved the date into your database/same table than simply put where condition (where date between dd/mm/yyyy and dd2/mm2/yyyy2 )with above solution.

NE☼

LEAVE A COMMENT