mercredi 27 mai 2015

PHP if statement error

My question is: Why does the script enter ALL if statements? Even if the "in array" question shouldn't let them.

First I show you the array which I am getting back from my model: In this case the array is just like array([0] => array()) because I only get 1 row back from my DB.

array(1) {
  [0]=>
  array(7) {
    ["Kunden_ID"]=>
    float(250)
    ["Kundentyp_ID"]=>
    float(1)
    ["kundentyp_row_id"]=>
    int(100)
    ["ext_kdnr"]=>
    float(0)
    ["kundentyp_anmerkung"]=>
    string(0) ""
    ["status"]=>
    string(0) ""
    ["name"]=>
    string(4) "ROLA" // Thats what we are looking for in our statements
  }
}

Now to the code:

    $result_array = $showAllgemeineKundendaten -> show_client_more($_SESSION['id'], 3); // get result array from model
    $rola = false; 
    $rola_pos = false;

    $rola_obc = false;
    $rola_obc_pos = false;

    $myto_fai = false;
    $myto_fai_pos = false;

    $omv = false;
    $omv_pos = false;

    $vat = false;
    $vat_pos = false;

    $plaketten = false;
    $plaketten_pos = false;

    $spedition = false;
    $spedition_pos = false;

    $moest = false;
    $moest_pos = false;

    $berufungen = false;
    $berufungen_pos = false;

    $diverse = false;
    $diverse_pos = false;

    $arr_length = count($result_array);
    echo $arr_length; // array length equals 1 since we only have 1 idx

    $rola_row = 0;
    $rola_obc_row = 0;
    $myto_fai_row = 0;
    $omv_row = 0;
    $vat_row = 0;
    $plaketten_row = 0;
    $spedition_row = 0;
    $moest_row = 0;
    $berufungen_row =0;
    $diverse_row = 0;

    echo "<pre>";
    var_dump($result_array);
    echo "</pre>";

    for($i = 0; $i < $arr_length; $i++){ // for runs only once since we only get 1 row back
        if(in_array("ROLA", $result_array[$i])){ 
// check if you find the string "ROLA" in the array idx $i
            $rola = true;
            $rola_pos = $i;
            $rola_row = $result_array[$i]["kundentyp_row_id"];
            echo "<br/>ROLA TYP AKTIV";
        }
        if(in_array("ROLA_OBC", $result_array[$i])){
            $rola_obc = true;
            $rola_obc_pos = $i;
            $rola_obc_row = $result_array[$i]["kundentyp_row_id"];
            echo "<br/>ROLA OBC TYP AKTIV";
        }
        if(in_array("MYTO_FAI", $result_array[$i])){
            $myto_fai = true;
            $myto_fai_pos = $i;
            $myto_fai = $result_array[$i]["kundentyp_row_id"];
            echo "<br/>MYTO FAI TYP AKTIV";
        }
        if(in_array("OMV", $result_array[$i])){
            $omv = true;
            $omv_pos = $i;
            $omv = $result_array[$i]["kundentyp_row_id"];
            echo "<br/>OMV TYP AKTIV";
        }
        if(in_array("VAT", $result_array[$i])){
            $vat = true;
            $vat_pos = $i;
            $vat = $result_array[$i]["kundentyp_row_id"];
            echo "<br/>VAT TYP AKTIV";
        }
        if(in_array("PLAKETTEN", $result_array[$i])){
            $plaketten = true;
            $plaketten_pos = $i;
            $plaketten = $result_array[$i]["kundentyp_row_id"];
            echo "<br/>PLAKETTEN TYP AKTIV";
        }
        if(in_array("SPEDITION", $result_array[$i])){
            $spedition = true;
            $spedition_pos = $i;
            $spedition = $result_array[$i]["kundentyp_row_id"];
            echo "<br/>SPEDITION TYP AKTIV";
        }
        if(in_array("MOEST", $result_array[$i])){
            $moest = true;
            $moest_pos = $i;
            $moest = $result_array[$i]["kundentyp_row_id"];
            echo "<br/>MOEST TYP AKTIV";
        }
        if(in_array("BERUFUNGEN", $result_array[$i])){
            $berufungen = true;
            $berufungen_pos = $i;
            $berufungen = $result_array[$i]["kundentyp_row_id"];
            echo "<br/>BERUFUNGEN TYP AKTIV";
        }
        if(in_array("DIVERSE", $result_array[$i])){
            $diverse = true;
            $diverse_pos = $i;
            $diverse = $result_array[$i]["kundentyp_row_id"];
            echo "<br/>DIVERSE TYP AKTIV";
        }
    }

As you see the result array contains the string "ROLA" therefore the first IF statement should be true and executed. Which is the case. BUT all other if statements appear to be true as well. Why?

Aucun commentaire:

Enregistrer un commentaire