Jump to content

will someone verify this logic please?


ahs10

Recommended Posts

i am updating some code and would like to know the logic behind my new code is correct.  here's my old code....

 

if (($data->sheets[0]['numCols'] > 9) ||

($data->sheets[0]['cells'][1][1] != "ID") ||

($data->sheets[0]['cells'][1][2] != "Date Submitted") ||

($data->sheets[0]['cells'][1][3] != "Group") ||

($data->sheets[0]['cells'][1][4] != "Comments")) {

    //do this

}

 

now i want to introduce a condition to those conditions, that depends on $userType.  it introduces $colCount to the logic, which i know will work fine, but i'm questioning the last line before the first curly brace....

 

if (($data->sheets[0]['numCols'] > $colCount) ||

($data->sheets[0]['cells'][1][1] != "ID") ||

($data->sheets[0]['cells'][1][2] != "Date Submitted") ||

($data->sheets[0]['cells'][1][3] != "Group") ||

($data->sheets[0]['cells'][1][4] != "Comments")) ||

(($data->sheets[0]['cells'][1][5] == "RVL") && ($userType == "Buda")) {

    //do this

}

 

i only want it to look for the RVL cell if the $userType is Buda.  i always want it to check the original conditions though, regardless.  is this correct?

Link to comment
Share on other sites

I would think it would be like this

    if (
      ($data->sheets[0]['numCols'] > $colCount ||
      $data->sheets[0]['cells'][1][1] != "ID" ||
      $data->sheets[0]['cells'][1][2] != "Date Submitted" ||
      $data->sheets[0]['cells'][1][3] != "Group" ||
      $data->sheets[0]['cells'][1][4] != "Comments")
      &&
      ($data->sheets[0]['cells'][1][5] == "RVL" && $userType == "Buda")
      )
    {
     //do this
}

 

Ray

Link to comment
Share on other sites

that's exactly where i got confused..... i should have stayed in school long enough to take at least one logic class... uggg.

 

so basically i have two condition sets, one that always needs to be checked and one that only needs to be checked if userType == Buda.

 

so you're saying that i need to say (condition set 1-always) && (condition set 2-sometimes), rather than (condition set 1-always) || (condition set 2-sometimes)?

 

now that i think about it, are you sure?  why would it be AND, not OR?

 

if cond1 AND cond2 == true.... but what if cond2 is false, i still want cond1 to execute if it's true... so it would be OR.

 

sorry, i'm thinking in my post.  thanks for sparking this thought, but i think my original was correct.  thanks again!

Link to comment
Share on other sites

You are right my bad. I read what you wanted wrong

 

you may have to check the buda first

    if ($userType == "Buda"){
      if(
      $data->sheets[0]['numCols'] > $colCount ||
      $data->sheets[0]['cells'][1][1] != "ID" ||
      $data->sheets[0]['cells'][1][2] != "Date Submitted" ||
      $data->sheets[0]['cells'][1][3] != "Group" ||
      $data->sheets[0]['cells'][1][4] != "Comments" ||
      $data->sheets[0]['cells'][1][5] == "RVL"){
      // do this

      }
    } else {
      if(
      $data->sheets[0]['numCols'] > $colCount ||
      $data->sheets[0]['cells'][1][1] != "ID" ||
      $data->sheets[0]['cells'][1][2] != "Date Submitted" ||
      $data->sheets[0]['cells'][1][3] != "Group" ||
      $data->sheets[0]['cells'][1][4] != "Comments"){
      // do this

      }
    }

 

Ray

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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