corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP IF logic


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author PHP IF logic
Steve
Premium Member

Avatar

Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
13th Apr 07 at 07:19   View Garage View User's Profile U2U Member Reply With Quote

Right basically I have two values that are the same, for arguments sake

$x1 = 200
$x2 = 200

Now i want to use some sort of IF statement or anyother statement you can think of to return a value if $x1 = or is greater than, or less than $x2 by 3

so for instance if $x1 = 198 it would return a vale, if $x = 201 it would return a value, but if $x1 = 190 then it woudnt do you see what im getting at?

I need a value to be return if $x1 is equal to or anywher in between + or - 3 each way of $x2

[Edited on 13-04-2007 by Steve]
Steve
Premium Member

Avatar

Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
13th Apr 07 at 07:33   View Garage View User's Profile U2U Member Reply With Quote

if there was n OR functionto use with IF i could do it easily but i cant find one??
AndyKent
Member

Registered: 3rd Sep 05
User status: Offline
13th Apr 07 at 08:04   View User's Profile U2U Member Reply With Quote

if(($x1 >= $x2-3)) && ($x1 <= $x2+3))

Does that work?

[Edited on 13-04-2007 by aPk]
Steve
Premium Member

Avatar

Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
13th Apr 07 at 08:15   View Garage View User's Profile U2U Member Reply With Quote

il try it in a sec, is || an equivalent of OR?
Rus
Member

Registered: 24th Jan 05
Location: SE London, Kent
User status: Offline
13th Apr 07 at 08:16   View User's Profile U2U Member Reply With Quote

yeah, thats flash actionscript though isn't it apk?
Steve
Premium Member

Avatar

Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
13th Apr 07 at 08:17   View Garage View User's Profile U2U Member Reply With Quote

thats php aswell
Steve
Premium Member

Avatar

Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
13th Apr 07 at 08:18   View Garage View User's Profile U2U Member Reply With Quote

quote:
Originally posted by aPk
if(($x1 >= $x2-3)) && ($x1 <= $x2+3))

Does that work?

[Edited on 13-04-2007 by aPk]


actually thinking about it that wont work as it will need both satisfying to return a value, that would work if the && weere replaced with an OR of some type. Would || work? ie

if(($x1 >= $x2-3)) || ($x1 <= $x2+3))
Rus
Member

Registered: 24th Jan 05
Location: SE London, Kent
User status: Offline
13th Apr 07 at 08:34   View User's Profile U2U Member Reply With Quote

var a:Number = 200;
var b:Number = 196;

if (a + 3 >= b && a - 3 <= b) {
trace("1");
} else {
trace("0");
}

there you go
AndyKent
Member

Registered: 3rd Sep 05
User status: Offline
13th Apr 07 at 09:48   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Steve
quote:
Originally posted by aPk
if(($x1 >= $x2-3)) && ($x1 <= $x2+3))

Does that work?

[Edited on 13-04-2007 by aPk]


actually thinking about it that wont work as it will need both satisfying to return a value, that would work if the && weere replaced with an OR of some type. Would || work? ie

if(($x1 >= $x2-3)) || ($x1 <= $x2+3))


No, because it would always evaluate as true

Ie. the if would ask if a number was larger or smaller than a constant which is always true (is a 50 larger or smaller than 100 - true).

And yes, thats PHP - I don't know flash

Rus - thats exactly what I came up with. Should work I'd have thought...

[Edited on 13-04-2007 by aPk]
AndyKent
Member

Registered: 3rd Sep 05
User status: Offline
13th Apr 07 at 09:52   View User's Profile U2U Member Reply With Quote

Thinking about it - you want to know if a number is >= or <= to a number by 3. My if statement will return true if so and not if false.

Sorted
Steve
Premium Member

Avatar

Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
13th Apr 07 at 10:03   View Garage View User's Profile U2U Member Reply With Quote

yeah cheers, iv sorted it and got it to work, but doesnt quite work how id liek so iv abaondoned the idea
AndyKent
Member

Registered: 3rd Sep 05
User status: Offline
13th Apr 07 at 10:03   View User's Profile U2U Member Reply With Quote

Rus
Member

Registered: 24th Jan 05
Location: SE London, Kent
User status: Offline
13th Apr 07 at 10:07   View User's Profile U2U Member Reply With Quote

AndyKent
Member

Registered: 3rd Sep 05
User status: Offline
13th Apr 07 at 10:10   View User's Profile U2U Member Reply With Quote

Wonder if someone can help me though actually....

I want to take a date that a user has entered and turn it into a date suitable to insert into MySQL.

The user would enter the date required (ie. 21/05/07) and it needs to be rearranged to read 2007-05-21 0000.

Any quick functions or have I got to split the string several times?
Steve
Premium Member

Avatar

Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
13th Apr 07 at 10:27   View Garage View User's Profile U2U Member Reply With Quote

use the php date function
AndyKent
Member

Registered: 3rd Sep 05
User status: Offline
13th Apr 07 at 10:33   View User's Profile U2U Member Reply With Quote

Will that know what to do with plain text?

Haven't tried it BTW.
ed
Member

Registered: 10th Sep 03
User status: Offline
13th Apr 07 at 10:59   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Steve
il try it in a sec, is || an equivalent of OR?
Yes.
Ste L
Member

Registered: 3rd Jul 06
Location: Manchester Drives: 106 16v Rallye
User status: Offline
13th Apr 07 at 11:26   View User's Profile U2U Member Reply With Quote

thought about useing "elseif"
Steve
Premium Member

Avatar

Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
13th Apr 07 at 12:14   View Garage View User's Profile U2U Member Reply With Quote

yes too long winded, done i wanted to anyway

apk

http://uk.php.net/date

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
Boolean Algebra cdcool1 General Chat 11 188
18th Mar 04 at 22:44
by vibrio
 
What car shall I get? Stu General Chat 81 2045
4th Oct 06 at 09:20
by Jambo
 
A few home entertainment questions... Jamie Walby Geek Day 37 2239
26th Oct 06 at 08:03
by Jamie Walby
 
Surround sound help........ Jamie Walby Geek Day 12 1206
20th Nov 06 at 15:02
by Cavey
 
Spanner in the works Ojc General Chat 367 9058
20th Dec 06 at 22:30
by whitter45
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP IF logic 28 database queries in 0.0223739 seconds