There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
PHP Conditions


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
CyBerAliEn's Avatar
Senior Member with 1,215 posts.
 
Join Date: Nov 2001
Location: Glendale, AZ, USA
25-Jun-2004, 02:52 PM #1
PHP Conditions
Got a question; don't remember how to do this.

Say I have the following code:

PHP Code:
<?php
$a 
"hello";
$b "goodbye";
$c "blah blah user input";
$d "other user input";

if (
$d=="$a")
{
    echo 
"alligator";
}

if (
$a==$c AND $d)
{
    echo 
"crocodile";
}
?>
The above is not supposed to make sense or anything but is just an example to refer to.

As you see in the second if statement, I want it to do something if "$a" is equal to "$c" and "$d". But I don't remember how you do the "AND" part (I know it isn't "AND", that is just there so you know what I'm trying to do ). Any help?


Thanks


Andrew
__________________
You cannot rationalize with the irrational. - Me

How many times do you let a horse kick you in the head before you stop going near horses? - Buck

Great spirits have always encountered violent opposition from mediocre minds. - Albert Einstein

Laptop:
2.4ghz Pentium 4, 40gb 7200 RPM HD, 512mb DDR RAM, 32mb Radeon 7500, DVD/CD-RW, Windows XP, (etc...)

Desktop:
1.5ghz Pentium 4, Seagate 40gb 7200 RPM & Seagate 160gb 7200 RPM HDs, 1.25gb RAM, Radeon 9200 128mb DDR, DVD, CD-RW, Windows XP, (etc...)

brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
25-Jun-2004, 04:42 PM #2
Actually, in PHP, you can use AND or two ampersands (&&). But that second if is just checking that $a==$c and $d exists. You should also use single quotes unless double quotes are really necessary, this will speed up processing time.

PHP Code:
<?php
$a 
'hello';
$b 'goodbye';
$c 'blah blah user input';
$d 'other user input'

if ($d==$a)
{
    echo 
'alligator';
}

if (
$a==$c AND $a==$d)
{
    echo 
'crocodile';
}
?>
punjabian263's Avatar
Senior Member with 316 posts.
 
Join Date: Mar 2003
Location: PAKISTAN
Experience: Advanced
26-Jun-2004, 10:22 PM #3
Code:
if ($a==$c AND $d)
or you can check as
Code:
if (($a==$c) AND $d)
The result will be true if $a and $c has same value and $d variable has any value.
CyBerAliEn's Avatar
Senior Member with 1,215 posts.
 
Join Date: Nov 2001
Location: Glendale, AZ, USA
27-Jun-2004, 01:40 AM #4
Processing time isn't really an issue, and frankly, the double quotes are merely just a habit.

So as I take it, if I had basically the following:

PHP Code:
<?php
if ($showamortization=="yes" AND $period=="yearly")
{
    echo 
"blah blah blah";
}
?>
Then "blah blah blah" would only be echoed if $showamortization was "yes" and period was "yearly". Correct?

Also a separate question: would the above work if "AND" was replaced with "OR" (obviously though, if either condition was true, it would process with OR; versuses AND, where both statements must be true)?

Also another question: can you have multiple AND's or OR's in a condition? Can you combine them, and if so, how does it process such a task (IE, what order)?

Thanks
__________________
You cannot rationalize with the irrational. - Me

How many times do you let a horse kick you in the head before you stop going near horses? - Buck

Great spirits have always encountered violent opposition from mediocre minds. - Albert Einstein

Laptop:
2.4ghz Pentium 4, 40gb 7200 RPM HD, 512mb DDR RAM, 32mb Radeon 7500, DVD/CD-RW, Windows XP, (etc...)

Desktop:
1.5ghz Pentium 4, Seagate 40gb 7200 RPM & Seagate 160gb 7200 RPM HDs, 1.25gb RAM, Radeon 9200 128mb DDR, DVD, CD-RW, Windows XP, (etc...)

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 05:44 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.