ex:subject type means g.k,english,maths etc... like that. my question is for preparing questionpapers by randomly selecting the questions of different questions
Can you please guide regarding this query....?
ex:subject type means g.k,english,maths etc... like that. my question is for preparing questionpapers by randomly selecting the questions of different questions
Can you please guide regarding this query....?
Maybe not the best solution but should work: use a SELECT
Query selecting the top 10 or 20 rows from a query ordered by RAND
eg:
SELECT * FROM questions_table WHERE subject='maths' ORDER BY RAND() LIMIT 0, 10
$sub1=$_POST['sub1'];
$no1=$_POST['no1'];
$sub2=$_POST['sub2'];
$no2=$_POST['no2'];
(assuming you are getting these values from a form)
mysql_query=('SELECT question FROM question_bank WHERE subject="'.$subj1.'" ORDER BY RAND() LIMIT $no1;
UNION
SELECT question FROM question_bank WHERE subject="'.$subj2.'" ORDER BY RAND() LIMIT $no2;')
.... so on... for all the subjects
If you want questions from all subjects you can use :
SELECT question FROM question_bank ORDER BY RAND() LIMIT 50;
here 50 is the maximum number of rows in the table upto which you want to search and select the questions.
Now, If you want a subject-wise selection, you can use
SELECT question FROM question_bank WHERE subject='GK' ORDER BY RAND() LIMIT 50;