topshelfbleu Posted October 15, 2010 Share Posted October 15, 2010 Hi I've got a qry that selects 100 questions one at a time from tblquestions. When the users have answered q100 I want them to be able to come out of the post-process-post loop that has taken them through the survey. My idea is that I could put an IF requirement in before the qry runs each time it selects the next question i.e. if $nextq <101 $result = mysql_query("SELECT oid,psc9 FROM tblquestions WHERE oid = $nextq"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; }; else echo "thanks you've finished now"; Two Questions: Is this the way I should be going about this problem? Have I got the syntax right? Many thanks! Nick Quote Link to comment https://forums.phpfreaks.com/topic/215950-the-if-command-running-a-qry-if-a-condition-is-met/ Share on other sites More sharing options...
premiso Posted October 15, 2010 Share Posted October 15, 2010 It will be far more efficient to query them all at once. $result = mysql_query("SELECT oid, psc9 FROM tblquestions ORDER BY oid LIMIT 100") or trigger_error("Question select failed with error: " . mysql_error()); if ($result !== false) { while ($row = mysql_fetch_assoc($result)) { echo 'Question: ' . $row['oid'] . ' psc9: ' . $row['psc9'] . '<br>'; } }else { echo 'The query returned an empty response, see the errors if any to resolve.'; } That should pull up all your rows sequentially for 100 rows. Quote Link to comment https://forums.phpfreaks.com/topic/215950-the-if-command-running-a-qry-if-a-condition-is-met/#findComment-1122519 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.