Jump to content

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


topshelfbleu

Recommended Posts

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

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.