Kaboom Kaboom - 11 months ago 46
MySQL Question

Generate a mysql query for each item in an array

I have an array with 3 values in it. These three values change depending on the user account (it's for referencing recovery questions by their id).

When they submit the form with their email address, the system checks it and if it exists gets their 3 recovery question id's which are store in a different database and the 3 answers from their account.

Then it stores the information into an array like so:

$questions = Array($question1id, $question2id, $question3id);

How can I make a
for this array that will query like so

Select * FROM recovery_questions WHERE rid='$val'

and return that for each question and store them in separate variables like
, and

Every time I try I overwrite the last value and its got me frustrated. Thanks

Answer Source
$a = 1;
$questions = Array($question1id, $question2id, $question3id);
foreach ($questions as $v){
    $sel = "Select * FROM recovery_questions WHERE rid='$v'";
    $stmt = $db->query($sel);
    while($r = $stmt->fetch()){
          $qvar = "cleanquestion".$a;
          $qqvar = $<<results>>

substitute results with whatever you get back from db.


  echo $cleanquestion1

will result with whatever result of question1id is.