IF && statement problem

Hello there,

My first time on the forums, glad to be here :slight_smile:

I'm completely new to programming in PHP and I have a question which I hope someone could help me with.

I am currently using this statement:

if(($session['cid'] == 2) && ($item['type'] == Dagger) && ($item2['type'] == Dagger)){
              $DualWield=", equip='10'";

I want it to also include this statement below to the above code:

($item['type'] == Fist Weapon) && ($item2['type'] == Fist Weapon)

I tried:

if(($session['cid'] == 2) && ($item['type'] == Dagger) && ($item2['type'] == Dagger)) || (($session['cid'] == 2) && ($item['type'] == Fist Weapon) && ($item2['type'] == Fist Weapon)) {

But I got a

Parse error:  syntax error, unexpected T_BOOLEAN_OR

Can anyone here help me and tell me how the above statement should be written? :slight_smile:

I suspect you can't do

if (expr) bool (expr)

in php. Try the following instead:

if (($session['cid'] == 2) && (($item['type'] == DAGGER) && ($item2['type'] == DAGGER)) || 
    (($item['type'] == FIST WEAPON) && ($item2['type']== FIST WEAPON)))

Andrew

Hi Andrew,

Thanks for offering to help, I tried using the statement rewrite you listed:

if(($session['cid'] == 2) && (($item['type'] == DAGGER) && ($item2['type'] == DAGGER)) || (($item['type'] == FIST WEAPON) && ($item2['type']== FIST WEAPON))){

but still no go, it gave me this error:

Parse error: syntax error, unexpected T_STRING on that line

Any suggestions?

What are 'Dagger' and 'Fist Weapon' anyway - variables, constants, strings? I noticed, but ignored, the fact that 'Fist weapon' had a space in it. If it is a variable then how did you get this far? If it is a string literal, ie you are looking for the word "dagger" in $item['type'] then you need to quote these strings. Knowing what you are doing here will help.

Andrew

Thanks for replying to my thread Andrew.

To answer your question, you are correct, I am looking for a word Dagger in $item['type']. The code was working fine when I use this statement below without putting Dagger in quotes:

if(($session['cid'] == 2) && ($item['type'] == Dagger) && ($item2['type'] == Dagger)){
$DualWield=", equip='10'";
However, when I tried to add the new statement to include Fist Weapons, that's when I ran into the problems with the errors.

Do you think I need to put quotes around Fist Weapons and leave the quotes off Dagger? Is that even possible without triggering errors.

To give you a little more insight on what the statement is suppose to do:

It is checking the database to see if cid (hero id) is 2 and the hero is holding a Dagger in hand 1 and Dagger in hand 2, then equip it for double wielding.

The new statement is so it will check to see if the hero (hero id) is 2, and if the hero is holding Fist Weapon in 1 hand, and another Fist Weapon in hand 2, then again, it will equip it for double wielding.

Any suggestions? It's just strange that the first line of code works perfectly for Daggers but when I try to add Fist Weapons in the statement, I get all the errors.

I don't know enough about php to know why it worked with unquoted "dagger" but I think it's good policy to quote all strings in any programming language. It might be worth investigating the string matching functions, too. Not only will it emphasize the fact that you are using strings but it gives you the option to ignore case if you like.

Andrew