vendredi 24 juillet 2015

Echo all incomplete surveys in mysqli

i'm trying to make a survey website where users will fill out surveys. I am trying to check what surveys are completed and echo all surveys that aren't. I currently have this code that echos a single survey after checking if it was completed or not.

    $_SESSION['id'] = $id;
    $completed1 = mysqli_query($con1,"SELECT * FROM completed WHERE surveyid = '1' AND userid = '$id'");
    $survey1 = mysqli_query($con1,"SELECT * FROM surveys WHERE id = '1'");
    if(mysqli_num_rows($completed1)>0){
     echo "Survey completed!";
    }
    elseif(mysqli_num_rows($survey1)>0){
      while($row = mysqli_fetch_array($survey1))
      echo $row["title"];
     }

First this code checks if a completed record exist in the completed table and if now it echos the specific survey from the surveys table. I want the code to be able to check what surveys have been completed by that user and echo all incomplete surveys.

I'm new to PHP so i really worked hard on this code but i'm completed lost when it comes to echoing all the surveys - i can only think of copying and pasting this code with each survey id. Any help is much appreciated!

I'm sure somebody knows how to easily achieve what i'm trying to do so i'm sorry if this was a simple issue, just started with php.

Aucun commentaire:

Enregistrer un commentaire