Hi guys...
I've got a form on my page which has around 50 drop down (select) boxes. It's a page of answers - as I output each question I use a mysql to see if the user has answers that particular question. If so, show their answer in the drop down.
It takes a long time to load when there are a lot of questions.... my question is should I do ONE sql at the beginning and store the result in an array, then loop through the array each time I load the question to see if there's an answer?
eg:
[sql]
#output the question
while ($row = mysql_fetch_array($question_res)) {
echo $row['question'] . " ";
$answer_res = mysql_query("SELECT * from answers WHERE question_id=".$row['question_id']."");
if (mysql_num_rows($answer_res) > 0) {
$answer = $row['answer'];
}
}
[/sql]
the above example is just something ive written now to show kinda how I get the answers. Would it be faster if I replaced the sql lookup for EACH question with an array loop??
So at the start, I'd get ALL the answers for this page then compare?
Any help is much appreciated! 🙂