SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    if statement with any number of or's

    I have an if statement and I need to check if any of the values are present and if so display it as below:

    Code:
    <? if ($data['Rottcause2']="Asphyxia") or ($data['Rottcause2']="Poison") { ?>
    <div id ="f1">
    <select name="rottcause" id="opts" onchange="showForm()" >
    <option value = "0">Select Option</option>
    <option value = "Asphyxia">Asphyxia</option>
    <option value = "Poison">Poison</option>
    <option value = "Drowning">Drowning</option>
    </select>
    </div>
    <? } else { ?>
    nope
    <? } ?>
    Need some help on the if or bit below as its not working

    Code:
    <? if ($data['Rottcause2']="Asphyxia") or ($data['Rottcause2']="Poison") { ?>

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,329
    Mentioned
    191 Post(s)
    Tagged
    4 Thread(s)
    Your syntax is incorrect.
    It should be written like this
    PHP Code:
    <? if ($data['Rottcause2']=="Asphyxia") || ($data['Rottcause2']=="Poison") { ?>
    In PHP (like many languages) the single equals (=) is an assignment operator and the double equals (==) is the comparison operator.
    Secondly, the OR operator is a double pipe (||).

    Hope this helps.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah yes, thank you ParkinT

  4. #4
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,329
    Mentioned
    191 Post(s)
    Tagged
    4 Thread(s)
    E X C E L L E N T

    Problem solved.
    Thread closed.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •