| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| RyanPrice.ca - Developer Join Date: Dec 2003
Posts: 1,328
![]() ![]() ![]() | PHP Parse Error... do you see it? I'm getting a parse error on line 20 - if ($x % 4 = 0) { For those who don't know, % is for modulus division (remainder division). Anyone see why I'm getting a parse error? PHP Code:
__________________ Ryan Price - Webmaster www.HostDurham.com - For Hosting | www.jeanco.ca - For Webdesign |
| |
| | #2 (permalink) |
| Senior Member Join Date: Aug 2002
Posts: 1,255
![]() ![]() | I think there's a few errors in there. You should have two equals signs there since you're comparing/evaluating rather than assigning. if ($x % 4 == 0) I'm not sure if that's why you're getting errors though. But I also noticed you have two else statements in a row. I think you need to change the last one to elseif or if. You're also missing some quotes and the semi-colon at the top where you declared your variables. |
| |
| | THREAD STARTER #3 (permalink) |
| RyanPrice.ca - Developer Join Date: Dec 2003
Posts: 1,328
![]() ![]() ![]() | Yup, thanks for catching the == error. I don't see anything wrong with how I declared variables at the top. The string has quotes and semicolon and the int variables have a semi colon. How do nested if statements work in PHP? I come from a VB background and am used to use the if x = 1 do something elseif do something else do soemthing end if Does php have an end if line of code? If not then how do you nest if statements?
__________________ Ryan Price - Webmaster www.HostDurham.com - For Hosting | www.jeanco.ca - For Webdesign |
| |
| | #4 (permalink) |
| NamePros Webmaster ![]() ![]() ![]() Join Date: Feb 2003
Posts: 12,930
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Hi Ryan, The format for php comparisons with elses: if ($x ==1) { >>do something<< } elseif ($x==2) { >> do something else << } else { >> do this << } You need to use a comparison with your elseif statement and you can't have two else statements on the same 'if'. |
| |
| | THREAD STARTER #5 (permalink) |
| RyanPrice.ca - Developer Join Date: Dec 2003
Posts: 1,328
![]() ![]() ![]() | Thanks RJ but thats not what I'm after. The first else statement was for the nested 'if' (the second if) and the other else statement was for the first 'if'. In VB this would've worked: ????: NamePros.com http://www.namepros.com/showthread.php?t=16186 Code: if x = whatever
if y = whatever
do this
else
do this
end if
else
do this
end if
__________________ Ryan Price - Webmaster www.HostDurham.com - For Hosting | www.jeanco.ca - For Webdesign |
| |
| | #6 (permalink) |
| NamePros Webmaster ![]() ![]() ![]() Join Date: Feb 2003
Posts: 12,930
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Yes, you can nest statements like that no problem. I think I misread your code initially because it was missing a closing bracket for one of your 'if' statements, it appeared as if there were two else statements on the same if. I see what you're trying to do now. PHP Code:
Last edited by -RJ-; 12-31-2003 at 12:47 PM.
|
| |
| | THREAD STARTER #7 (permalink) |
| RyanPrice.ca - Developer Join Date: Dec 2003
Posts: 1,328
![]() ![]() ![]() | Ah I see... just need another } Thanks
__________________ Ryan Price - Webmaster www.HostDurham.com - For Hosting | www.jeanco.ca - For Webdesign |
| |
| | #8 (permalink) | ||||
| Senior Member Join Date: Aug 2002
Posts: 1,255
![]() ![]() |
Oops! LOL I just took a quick look at it and I was looking where you have the multi line comments up at the top. That's why I thought you were missing some quotes and such. ![]() And I also thought there was only one if statement which is why I was confused with both your else statements in a row like that. But I see them now. | ||||
| |