GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Quick PHP Question. (https://gfy.com/showthread.php?t=1004236)

Jdoughs 01-02-2011 04:59 AM

Quick PHP Question.
 
I've got a check to see if it's a certain producttype (dog), and if so, something fits. Question is, can I have it be 'dog' and 'cat' and still have it as a line and not going into a if/else?

<-- Total noob, just learning.

Thanks in advance and Happy New Year.

PHP Code:

<?php if($this->product->productType == 'dog') { ?>        ruff ruff ruff            <?php ?>

Code:

<?php if($this->product->productType == 'dog') { ?>                ruff ruff ruff                        <?php } ?>

MrGusMuller 01-02-2011 05:09 AM

Sorry, but I havent understood ur question.
I have a lousy english.
But you have a variable set to be "dog" how can it be "dog" and "cat" at the same time?

<?php if($this->product->productType == 'dog' or $this->product->productType == 'cat') { ?>

Jdoughs 01-02-2011 05:19 AM

Yes that is what I meant "OR".

If it is dog or cat. (could be both) I guess, bowls, toys, I don't know :)

THANKS!

grumpy 01-02-2011 05:29 AM

if( item==dog or item==cat ){ do stuff }

cooldude7 01-02-2011 08:43 AM

Quote:

Originally Posted by grumpy (Post 17813380)
if( item==dog or item==cat ){ do stuff }

do stuff with whom ? :1orglaugh:1orglaugh

Sexgenoten 01-02-2011 08:55 AM

I'd start by seperating your scripting layer from you presentation layer.

Perhaps using a ''switch" could help you as well.

Quote:

$var = 'dog';

switch( $var ){
case 'dog':
echo "woef woef";
break;

case 'cat':
echo "miauw";
break;

default:
echo "no cat or dog found";

}


bl4h 01-02-2011 11:37 AM

wtf ? am I missing something here :1orglaugh


Code:

if($this->product->productType == "dog" || $this->product->productType == "cat") { }
the two pipes between them means "OR".

|| = OR
&& = AND

I mean I wouldnt do it that way but that answer your question about and and or.

Adultlexicon 01-02-2011 12:06 PM

Check PHP.net its full of examples

r0bman 01-02-2011 02:06 PM

Quote:

Originally Posted by bl4h (Post 17813770)
wtf ? am I missing something here :1orglaugh


Code:

if($this->product->productType == "dog" || $this->product->productType == "cat") { }
the two pipes between them means "OR".

|| = OR
&& = AND

I mean I wouldnt do it that way but that answer your question about and and or.

This is the correct way unless you are comparing more than a few product types (Cat, Dog, Horse, Pig) If so, use the switch statement.


All times are GMT -7. The time now is 07:36 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123