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)
-   -   Extremely basic PHP help needed. (https://gfy.com/showthread.php?t=101080)

chodadog 01-19-2003 01:14 AM

Extremely basic PHP help needed.
 
Okay, i've already got this..

PHP Code:

<?php echo $HTTP_GET_VARS['w']; ?>

Which is fine, but i'd like some sort of if/else thingy. Example, if w is null (index.php?w=), then make w=9999999 or if the w variable isn't passed at all (index.php), then make w=9999999.

Hopefully that actually makes sense. I'm so very clueless when it comes to this shit.

psyko514 01-19-2003 01:20 AM

PHP Code:

<? if (!isset($w)) { $w = 999999; } ?>


SilverTab 01-19-2003 01:22 AM

If w is a variable you can check with

if (empty($w))
{
...
}
else
{
...
}

not sure if I get what you mean tough!

chodadog 01-19-2003 01:36 AM

SilverTab, thanks. That's exactly what i was looking for. psyko, thanks too, but not exactly sure what to do with what you gave me! But thanks anyways. Sorry for being so unclear in the first place.

SilverTab 01-19-2003 01:50 AM

Np !...glad I could be helpful :winkwink:

psyko514 01-19-2003 01:58 AM

Chodadog... the isset() function checks to see if the variable has been set (if it has a value). if so, it gives a result of TRUE.

the code i posted checks to see if W has been given a value, and if not, it gives W a value of 99999 or whatever else you want.

i posted it in one line, but it could be broken into several lines

PHP Code:

<?php
if (!isset($w)) {
   
$w 999999

?>

the empty() function does more or less the same thing... except that if W = 0, isset() will return TRUE but empty() will return FALSE

SilverTab 01-19-2003 02:12 AM

Quote:

Originally posted by psyko514

the empty() function does more or less the same thing... except that if W = 0, isset() will return TRUE but empty() will return FALSE

Yup..Always more than one ways to get to the same result in programming :winkwink:

Cogitator 01-19-2003 02:39 PM

I always create a function like:
PHP Code:

<?
function GetValue($var, $default) {
    if (isset($var) {
        return $var;
    } else {
        return $default;
    }
}
?>

// you would use it as follows:

<?
echo GetValue($w, 999999);
?>


Bad B0y 01-19-2003 03:03 PM

another way(not tested btw) just cuz i have nothing better to do after i've watered the plants and taken my special pills. :thumbsup

$w = empty($w) ? 999999 : $w;


All times are GMT -7. The time now is 07:40 AM.

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