473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

IF statements not working...

The1corrupted
134 100+
I need help. These if statements don't work like they should... [PHP]
/*Array Info that is being pulled from the room table:
0 = ID
1 = Title
2 = Description

3 = North
4 = South
5 = East
6 = West
7 = Up
8 = Down

9 = X coord
10 = Y coord
11 = Z coord
*/
if ($dir == 1 AND $ray[3] == 1) {
++$_SESSION['xcoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
} else {
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}
if ($dir == 2 AND $ray[5] == 1) {
++$_SESSION['ycoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
} else {
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}
if ($dir == 3 AND $ray[4] == 1) {
--$_SESSION['xcoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
} else {
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}
if ($dir == 4 AND $ray[6] == 1) {
--$_SESSION['ycoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
} else {
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}
if ($dir == 5 AND $ray[7] == 1) {
++$_SESSION['zcoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
} else {
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}
if ($dir == 6 AND $ray[8] == 1) {
--$_SESSION['zcoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
} else {
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}[/PHP] Am I doing too much coding or would it be something in the array?

$dir = Move command
$ray[number] = 1 or 0 with 1 being TRUE and 0 being FALSE
$_SESSION['x/y/zcoord'] = Coordinate Plane
Feb 22 '07 #1
16 2061
ronverdonk
4,258 Expert 4TB
I don't understand exactly what is not working. To me the statements are perfectly legal but that is obviously not how you see it.

Maybe what bothers you is: when $dir==6 it will execute all the ELSE branches of if ($dir==1) ...., if ($dir==2) .... etc. Correct?

Ronald :cool:
Feb 22 '07 #2
The1corrupted
134 100+
No, it just flat doesn't work. Those are supposed to be walls, preventing users from walking off the map and into a void. They work perfectly for the Z coords but not for the X and Y...
Feb 22 '07 #3
ronverdonk
4,258 Expert 4TB
This is your culprit statement:
[php]if ($dir == 1 AND $ray[3] == 1) {
++$_SESSION['xcoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
} else {
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}
[/php]
Example:
when $dir is not equal to 1 and $ray[3] not equal to 1 you will execute the ELSE branch of this statement. So when your $dir equals 3 and $ray[4] equals 1 it will never get to the statement that tests that condition because the first IF block (shown above) already threw you out.

Ronald :cool:
Feb 22 '07 #4
The1corrupted
134 100+
This is your culprit statement:
[php]if ($dir == 1 AND $ray[3] == 1) {
++$_SESSION['xcoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
} else {
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}
[/php]
Example:
when $dir is not equal to 1 and $ray[3] not equal to 1 you will execute the ELSE branch of this statement. So when your $dir equals 3 and $ray[4] equals 1 it will never get to the statement that tests that condition because the first IF block (shown above) already threw you out.

Ronald :cool:
I don't quite follow you.. When $ray[3] does not equal one, it just goes through the first process like nothing's happened. Should I make it an if statement within an if statement?
Feb 22 '07 #5
ronverdonk
4,258 Expert 4TB
I don't quite follow you.. When $ray[3] does not equal one, it just goes through the first process like nothing's happened. Should I make it an if statement within an if statement?
[php]if ($dir == 1 AND $ray[3] == 1) {
++$_SESSION['xcoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
} else {
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}
[/php]
If $dir equals 1 and $ray[3] does not equal 1 it executes the ELSE branch.
If $dir not equals 1 and $ray[3] equals 1 it executes the ELSE branch
if $dir not equals 1 and $ray[3] not equals 1 it executes the ELSE branch.
[php]echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";[/php]

You are testing an AND relation, so when either or both are not true, it will execute the ELSE branch.

Ronald :cool:
Feb 22 '07 #6
The1corrupted
134 100+
Even if I split them into two separate if statements like so:
[PHP]if ($var == 1) {
if ($var2 == 1) {
--/++$_SESSION['coord'];
echo "<meta tag>";
} else {
echo "<meta tag";
}[/PHP]
it still won't work properly.
Feb 22 '07 #7
ronverdonk
4,258 Expert 4TB
Why don't you mjust stick with the 'positive' outcome of the if comparisons? Like this:
[php]
if ($dir == 1 AND $ray[3] == 1) {
++$_SESSION['xcoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}
if ($dir == 2 AND $ray[5] == 1) {
++$_SESSION['ycoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}
if ($dir == 3 AND $ray[4] == 1) {
--$_SESSION['xcoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}
if ($dir == 4 AND $ray[6] == 1) {
--$_SESSION['ycoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}
if ($dir == 5 AND $ray[7] == 1) {
++$_SESSION['zcoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}
if ($dir == 6 AND $ray[8] == 1) {
--$_SESSION['zcoord'];
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
}
else {
echo "<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";
} [/php]

Ronald :cool:
Feb 22 '07 #8
The1corrupted
134 100+
Because the roomdisp is a completely separate file and does something entirely different than what is occurring on this page. This page is called more2.php and it is being posted to by admin_input.php. So if moving in a paticular direction is false, then I want to simply refresh roomdisp without changing the session coords.
Feb 22 '07 #9
ronverdonk
4,258 Expert 4TB
Because the roomdisp is a completely separate file and does something entirely different than what is occurring on this page. This page is called more2.php and it is being posted to by admin_input.php. So if moving in a paticular direction is false, then I want to simply refresh roomdisp without changing the session coords.
But that is exactly what my snippet is doing. If none of the 'if' statement value combinations validate, script roomdisp.php is called without any $_SESSION['xxx'] updates.

Ronald :cool:
Feb 22 '07 #10
The1corrupted
134 100+
Ah... I'll try it out, then.
Feb 22 '07 #11
The1corrupted
134 100+
Didn't work. Users will still walk straight into a void. *laughs* Those poor souls.
Feb 22 '07 #12
ronverdonk
4,258 Expert 4TB
Maybe I don't really understand what you are trying to achieve. My snippet steers your users to [php]"<META HTTP-EQUIV='refresh' content='0; url=roomdisp.php'>";[/php] when none of the conditions is met. Maybe I don't understand what you are trying to achieve. If so, please be patient and explain it, because I am lost here.

Ronald :cool:
Feb 22 '07 #13
The1corrupted
134 100+
Okay... from the ground up...

1. User is in a place

2. User tries to move north (for the sake of example)

3. Query the mysql database to see if that is possible

3a. If possible, user's coordinates change + or - 1 and refresh display

3b. If not possible, user's display simply refreshes and nothing changes.
Feb 22 '07 #14
ronverdonk
4,258 Expert 4TB
It is 2.20 am. I quit. See ya tomorrow.

Ronald :cool:
Feb 22 '07 #15
The1corrupted
134 100+
Okay... I'll see if I can get it fixed in the mean time.
Feb 22 '07 #16
The1corrupted
134 100+
Nevermind. I fixed the misbehaving if statements with $_SESSION['vars'] all over the place. I love these little gadgets...
Feb 22 '07 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: dmbkiwi | last post by:
I am new to this group, and relatively new to python programming, however, have encountered a problem I just cannot solve through reading the documentation, and searching this group on google. I...
9
by: Jaime Wyant | last post by:
I know I've seen this somewhere, but can't seem to google it. Is there a way to use an alternate statement separator, other than the default ';'? jw
2
by: Andreas Paasch | last post by:
I'm having a little problem here that seems difficult to solve - to me. I'm working on several tables at one time and once in a while I need to update them based on a previous select statement....
4
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from...
2
by: Annie D via AccessMonster.com | last post by:
Hi, Is it possible to use multiple statements in SQL?? (I’ve never used it before) : I have one query that i'm working with, The statements I want to use are as below, they all work...
35
by: David Cleaver | last post by:
Hello all, I was wondering if there were some sort of limitations on the "if" statement? I'm writing a program which needs to check a bunch of conditions all at the same time (basically). And...
1
by: ickypick | last post by:
I am writing a parser to read in ftp log files and insert into a databse. I have everything working fine, except the legacy billing system being used generates bills for each user instead of the...
2
by: ALi Shaikh | last post by:
Hey switch statements are not working it gives me errors saying "case" illegal use of word. heres the code //Chinese calender Project #include <iostream.h> int main() { int year; int myear;...
0
by: Germaris | last post by:
Hi there! Would you please tell me why the _visible statements are not working in the code below? Many thanks in advance for your help and suggestions. Regards Gerry
1
by: jock1up | last post by:
Been working on some programming exercises in my spare time and don't fully understand this one related to ADO....Appreciate any help on this. The name of the ADO data control is adoNum-----Was...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.