/    Sign up×
Community /Pin to ProfileBookmark

MySQL / PHP – IF/AND/OR Statements – Getting Confused

I’m updating some PHP/MySQL code and struggling to get it to work correctly.

At the moment I have the code as follows:

`if (strlen($number) < “9” AND $number1 <> “101”){

}

else if (strlen($number) > “14”) {
}

else {
………..the rest of the code goes here to action after filtering out the above.`

I want the first if command to match if the length is less than 9 characters long, and the $number1 is either 101 or (I want to add in 102).

I’ve tried amending the first IF statement to read as follows, but that fails:

`if (strlen($number) < “9” AND ($number1 <> “101”) OR ($number1 <> “102”)){

}`

I’m expecting it to be something very straightforward, but I’ve looked at it for so long now I just cannot see it.

Thanks in advance for any help.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@tracknutMay 23.2020 — From the way you've worded this:
I want the first if command to match if the length is less than 9 characters long, and the $number1 is either 101 or (I want to add in 102).[/quote]
You want to replace your not-equals, with equals and add some parenthesis in:
<i>
</i>if (strlen($number) &lt; "9" AND (($number1 == "101") OR ($number1 == "102")))


By the way, using the strings for number there is rather jarring. What about:
<i>
</i>if (strlen($number) &lt; 9 AND (($number1 == 101) OR ($number1 == 102)))
Copy linkTweet thisAlerts:
@djb2002authorMay 23.2020 — Thanks for your help - It is really appreciated.
×

Success!

Help @djb2002 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...