Passing values through a variable in PHP

I am having a few issues with a basic program I am working on: I am aiming to take the 4 learning dimensions from the table indexLearningStyle such as (Mildly active, moderately active and so on) I am then aiming to print feedback from the ilsFeedback table based on the previous dimensions. However regardless of the preempting value such as Mildy or Strongly I want to print general feedback.

<?php

    $mildlyActive = "active";
    $moderatelyActive = "active";
    $stronglyActive = "active";

    $mildlyReflective = "reflective";
    $moderatelyReflective = "reflective";
    $stronglyReflective = "reflective";

    $mildlySensing = "sensing";
    $moderatelySensing = "sensing";
    $stronglySensing = "sensing";

    $mildlyIntuitive = "intuitive";
    $moderatelyIntuitive = "intuitive";
    $stronglyIntuitive = "intuitive";

    $mildlyVisual = "visual";
    $moderatelyVisual = "visual";
    $stronglyVisual = "visual";

    $mildlyVerbal = "verbal";
    $moderatelyVerbal = "verbal";
    $stronglyVerbal = "verbal";

    $mildlySequential = "sequential";
    $moderatelySequential = "sequential";
    $stronglySequential = "sequential";

    $mildlyGlobal = "global";
    $moderatelyGlobal = "global";
    $stronglyGlobal = "global";

    $dbQuery = $db->prepare("select dimension1, dimension2, dimension3, dimension4 FROM indexLearningStyle WHERE studentNumber = '".$currentUser."'");
    $dbQuery-> execute();

    while ($dbRow = $dbQuery->fetch (PDO::FETCH_ASSOC)) {
    $dimension1 = $dbRow["dimension1"];
    $dimension2 = $dbRow["dimension2"];
    $dimension3 = $dbRow["dimension3"];
    $dimension4 = $dbRow["dimension4"]; 

    }

    $dbQuery = $db->prepare("select answerType, studentDefinition FROM ilsFeedback");
    $dbQuery-> execute();

    while ($dbRow = $dbQuery->fetch (PDO::FETCH_ASSOC)) {
    $answerType = $dbRow["answerType"];
    $studentDefinition = $dbRow["studentDefinition"];

    }

    if ($dimension1 = $mildlyActive or $moderatelyActive or $stronglyActive){
    $dbQuery = $db->prepare("select answerType, studentDefinition FROM ilsFeedback WHERE answerType = 'active'");
    $dbQuery-> execute();
    $studentDefinition = $dbRow["studentDefinition"];
    echo $studentDefinition;
    }
else {
    if ($dimension1 = $mildlyReflective or $moderatelyReflective or $stronglyReflective){
    $dbQuery = $db->prepare("select answerType, studentDefinition FROM ilsFeedback WHERE answerType = 'reflective'");
    $dbQuery-> execute();

    $studentDefinition = "studentDefinition";
    echo $studentDefinition;
    }
}




?>  

1 answer

  • answered 2018-04-14 15:42 sami

    i think that in this line

    if ($dimension1 = $mildlyActive or $moderatelyActive or $stronglyActive){
    

    must be

     if ($dimension1 == $mildlyActive || $dimension1 == $moderatelyActive || 
     $dimension1 == $stronglyActive){
    

    and the same proplem with this

    if ($dimension1 = $mildlyReflective or $moderatelyReflective or $stronglyReflective){
    

    must be

         if ($dimension1 == $mildlyReflective || $dimension1 == $moderatelyReflective || $dimension1 == $stronglyReflective){
    

    hint: yo can use elseif($dimension1 == $mildlyReflective) { instead of else { if($dimension1 == $mildlyReflective)