mysql query & php - how to achieve this?
<p>Okay, so I have a table, with 20 fields named <code>q1, q2, q3 all the way to q20</code></p>

<p>These fields contain answers, which is a number out of 10.</p>

<p>I want to basically choose 10 questions at random, and do some maths and the php to display it on page.</p>

<p>Here is what I have so far:</p>

<pre><code>$selector = "10218";
/* Work out how many rows to divide by */
$nr = mysql_query("SELECT * FROM `reviews` WHERE `selector` = '" . $selector . "'");
$nr = mysql_num_rows($nr);
/* Get the total sum of answers for question 1  */
$q1 = mysql_query("SELECT sum(`q1`) AS `sum` FROM `reviews` WHERE `selector` = '" . $selector. "'");
$q1 = mysql_fetch_array($q1);
$q1 = $q1['sum'] / $nr;
echo "q1 avg is " . round($q1);
</code></pre>

<p>Basically, we want to do this for 10 questions - at random.</p>

<p>We don't want to have to write this code out 20 times, as it is quite strenuous and we want to do some sort of "array" to contain the questions in, and then a for each loop to loop 10 times with a random question?</p>

<p>We want to end up with:</p>

<pre><code>q1 avg is 8
q2 avg is 4
q9 avg is 7
q4 avg is 8
q14 avg is 4
q18 avg is 6
q12 avg is 3
q7 avg is 10
q20 avg is 8
q13 avg is 9
</code></pre>

<p>How can we go about doing this? If you didn't understand let me know and I'll try rephrase it.</p>
