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)
-   -   PHP coders - quick question (https://gfy.com/showthread.php?t=411339)

fusionx 01-01-2005 09:54 PM

PHP coders - quick question
 
How do I do this:

IF $_GET['cat'] = 0 OR $_GET['cat'] IS NULL
myCat = 0
else
myCat = $_GET['cat']
END IF

Basically, if there is a request var called "cat" and it is zero, null, or if it doesn't even exist, set a var myCat to zero.
Otherwise, set the var to whatever it currently contains.

Thanks in advance!

Aric 01-01-2005 09:59 PM

if(!empty($_GET['cat']))
$myCat = $_GET['cat'];
else
$myCat = defaultValue;

fusionx 01-01-2005 10:01 PM

Quote:

Originally Posted by Aric
if(!empty($_GET['cat']))
$myCat = $_GET['cat'];
else
$myCat = defaultValue;

Isl ?cat=0 still considered empty?

Aric 01-01-2005 10:03 PM

as far as I know in newer versions of PHP, 0 is empty.. you can also use

!isset($_GET['cat']) if !empty() doesn't work out for ya :)

fusionx 01-01-2005 10:12 PM

Thanks very much! It works well.

richard 01-02-2005 03:52 AM

empty($_GET["cat"]) ? ($myCat=0) : ($myCat=$_GET["cat"]);

That's basically what i use.

hyper 01-02-2005 03:55 AM

i use isset

opflix 01-02-2005 04:03 AM

Quote:

Originally Posted by Aric
if(!empty($_GET['cat']))
$myCat = $_GET['cat'];
else
$myCat = defaultValue;


aric, do u have a site or offer programming services? lmk... i have a project if u r available - thanks!

...

grumpy 01-02-2005 04:06 AM

if($_GET['cat'] < 1){$_GET['cat']=0}

woj 01-02-2005 05:25 AM

if cat is a numeric value, like a category id or something, you can do:
$myCat=intval($_GET['cat']);

Voodoo 01-02-2005 05:26 AM

WHEN WILL YOU LEARN!?!?!?!? "Quick Questions" NEVER have "quick answers".


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

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