Jump to content

the IF command. Running a qry if a condition is met.


Recommended Posts


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




if $nextq <101
  $result = mysql_query("SELECT oid,psc9 FROM tblquestions WHERE oid = $nextq");
if (!$result) {
    echo 'Could not run query: ' . mysql_error();
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!




Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.