Forum Moderators: coopster
$result = mysql_query("SELECT *,MD5( RAND( ) ) AS RandQues FROM questions ORDER BY RandQues DESC LIMIT 50 ");
The "MD5( RAND( ) ) AS RandQues" creates a random number which is assigned to each entry, you then sort by this random number.
ta,
Hughie
set your table 'questions' up like:
ID,Question_Contents,Question_Answer
then in your php:
<?php
$result = mysql_query("SELECT *,MD5( RAND( ) ) AS RandQues FROM questions ORDER BY RandQues DESC LIMIT 50 ");
$count=0;
while($row=mysql_fetch_array($result))
{
$count+=1;
$text.='Question '.$count.'<br>
'.$row['Question_Contents'].'<br><br>';
}
echo $text;
?>
That should output
question 1
This is question one
Question 2
This is Question 2
etc....
no matter what order they come out as they will always be question 1, 2, 3 etc.
Is that what your after?
ta,
hughie
{QUESTION ONE INSERTED HERE AUTOMATICALLY}
<label>
<input type="radio" name="q1" value="1">
Strongly Agree</label>
<br>
<label>
<input type="radio" name="q1" value="2">
Agree</label>
<br>
<label>
<input type="radio" name="q1" value="3">
Unsure</label>
<br>
<label>
<input type="radio" name="q1" value="4">
Disagree</label>
<br>
<label>
<input type="radio" name="q1" value="5">
Strongly Disagree</label>
<input type="submit" value="submit">
$count=0;
while($row=mysql_fetch_array($result))
{
$count+=1;
$text.='<b>Question '.$count.'</b><br>
'.$row['Question_Contents'].'<br>
<label>
<input type="radio" name="q'.$count.'" value="1">
Strongly Agree</label>
<br>
<label>
<input type="radio" name="q'.$count.'" value="2">
Agree</label>
<br>
<label>
<input type="radio" name="q'.$count.'" value="3">
Unsure</label>
<br>
<label>
<input type="radio" name="q'.$count.'" value="4">
Disagree</label>
<br>
<label>
<input type="radio" name="q'.$count.'" value="5">
Strongly Disagree</label>
<br><br>';
}
echo $text;
?>
looping through the while loop for 50 questions
If your new to php and mysql, have a look on hotscripts.com in the php section, there are lots of scripts available to download. pick one of those apart and see how they do it, its a good way of getting to grips with things.
There are probably some nice tutorials out there as well.
ta,
Hugie
How can I create short variables names for each response, to carry forward onto my next page?
If I was writing this without the randomization, I would use something like these:
// create short variable names
$q1=$HTTP_POST_VARS['q1'];
$q2=$HTTP_POST_VARS['q2'];
$q3=$HTTP_POST_VARS['q3'];
$q4=$HTTP_POST_VARS['q4'];
$q5=$HTTP_POST_VARS['q5'];
// etc.
$query = "insert into items values
('".$q1."', '".$q2."', '".$q3."', '".$q4."', '".$q5."')";
// to enter questions 1 to 5 into the table
But in the code above, there is only:
name="q'.$count.'
Many thanks