close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Syntax has me baffled

Thread began 9/24/2009 11:18 pm by tom92909 | Last modified 9/25/2009 3:43 pm by Jason Byrnes | 1730 views | 6 replies |

tom92909Beta Tester

Syntax has me baffled

I need to run two numeric variables through a series "IF statements"...??? Unless there's a better way...

Here are my parameters... ( I do realize that what I'm typing in the code below is in NO WAY proper syntax, I'm just trying to ensure that I'm explaining myself clearly)

php:
IF $x is even

   AND $y is even  ( do nothing)

IF $x is odd
   AND $y is odd  ( do nothing)

IF $x is even
   AND $y is odd  ( $y = $y+1)

IF $x is odd
   AND $y is even  ( $y = $y+1)



I've run into a wall here and need a helping hand.

Thanks!

Tom

Sign in to reply to this post

anonymous

Tom,

You could either do a modified if statement or a case and switch statement. I think since two of your if statements should result in the same action, you would be best with a modified if statement like this:

php:
if (($x%2=0 AND $y%2=0) OR ($x%2!=0 AND $y%2!=0)) {

DO NOTHING
  
} elseif (($x%2=0 AND $y%2!=0) OR ($x%2!=0 AND $y%2=0)) {

GO CRAZY

}
Sign in to reply to this post

tom92909Beta Tester

hmmm, I'm not getting a positive result with that either.

php:
<?php

$min 
=5;
$max =12;
if ((
$min %AND $max %0) OR ($min %!= AND $max %!= 0)) {
} elseif ((
$min %AND $max %!= 0) OR ($min %!=AND $max %0)) {
$max $max+1;
}  
echo 
"$min";
echo 
"$max";
?>



The above code produces the following error...

  Parse error: syntax error, unexpected '=' on line 3  



The following code will produce an echo result of "3 is odd"

php:
<?php

$i
=3;
if (
$i 2) {
echo 
"$i is odd";
} else {
echo 
"$i is even";
}
?>



So I'm still baffled on syntax...

Sign in to reply to this post

tom92909Beta Tester

PHP makes efficient work out of my problem.

php:
if($x%2 != $y%2) {

$y++;
}



Crazy simple solution. Cheers to PHP!

Sign in to reply to this post

Jason ByrnesWebAssist

The error you where getting was because og the way you where doing the comparisons.


in this line:

php:
if (($min %2 = 0 AND $max %2 = 0) OR ($min %2 != 0 AND $max %2 != 0)) {



this code is setting the result:
$min %2 = 0


to do an equals comparison in PHP, it should be:
$min %2 == 0


so that line should be:

php:
if (($min %2 == 0 AND $max %2 == 0) OR ($min %2 != 0 AND $max %2 != 0)) {
Sign in to reply to this post

tom92909Beta Tester

Jason,

Thanks for the clarification, that kinda helped, but I'm not really getting the output I wanted.

Let me explain again what I'm needing.

I have (2) dynamic numbers.
$x = 5;
$y = 14;

so my issue is how do I check for the following conditions...

IF $x < 0 ($x=0)
IF $x is even
AND $y is even ( do nothing)

IF $x < 0 ($x=0)
IF $x is odd
AND $y is odd ( do nothing)

IF $x < 0 ($x=0)
IF $x is even
AND $y is odd ( $y++)

IF $x < 0 ($x=0)
IF $x is odd
AND $y is even ( $y++)


I'm a bit lost how to write the statement to get the above.
I hope that I've explained myself better this time.

Sign in to reply to this post

Jason ByrnesWebAssist

try the following:

php:
if($x < 0) $x = 0; 
if (($x%2==0 AND $y%2!=0) OR ($x%2!=0 AND $y%2==0)) $y++;




If that does not give the desired results, please explain what the outcome is and how it differs from what you are trying to accomplish.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...