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 gods, I need your help please! (https://gfy.com/showthread.php?t=1042911)

alan-l 10-23-2011 10:21 PM

PHP gods, I need your help please!
 
Need to fix this in a script and the developer is MIA, any help greatly appreciated. I have this line:

Code:

<?php echo $product['niche'][0]; ?>
which throws whatever I input in the admin area for that field. Like Niche: Latex Fetish.

However, if I don't input something in that field, the design gets screwed since the divs are floated or whatever, so what I need is just something like

Code:

if $product['niche'][0]; is filled, then use it, otherwise add N/A
I know it's something extremely easy, but I have no idea about PHP, so any help more han appreciated :thumbsup

Of course, thank you in advance :)

KickAssJesse 10-23-2011 10:24 PM

PHP Code:

if ($product['niche'][0]) { echo $product['niche'][0]; } 

:thumbsup

alan-l 10-23-2011 10:27 PM

Quote:

Originally Posted by KickAssJesse (Post 18511119)
PHP Code:

if ($product['niche'][0]) { echo $product['niche'][0]; } 

:thumbsup

wow, thank you that was fast, but I really need to add something on that field, how do I make it show 'N/A' when field is empty?

KickAssJesse 10-23-2011 10:30 PM

PHP Code:

if ($product['niche'][0]) { echo $product['niche'][0]; } 
else { echo 
'N/A'; } 


Jakez 10-23-2011 10:30 PM

Quote:

Originally Posted by KickAssJesse (Post 18511119)
PHP Code:

if ($product['niche'][0]) { echo $product['niche'][0]; } 

:thumbsup

PHP Code:

if ($product['niche'][0]) { echo $product['niche'][0]; } else { echo 'N/A'; } 


alan-l 10-23-2011 10:34 PM

thank you guys, that worked like a charm! :thumbsup

Tempest 10-23-2011 10:35 PM

Code:

if( isset($product['niche'][0]) && $product['niche'][0] != ''){
    echo $product['niche'][0];
}else{
    echo 'N/A';
}


blackmonsters 10-23-2011 10:45 PM

Quote:

Originally Posted by Tempest (Post 18511139)
Code:

if( isset($product['niche'][0]) && $product['niche'][0] != ''){
    echo $product['niche'][0];
}else{
    echo 'N/A';
}


This is better.

dissipate 10-23-2011 11:34 PM

print !empty($product['niche'][0]) ? $product['niche'][0] : "N/A";

V_RocKs 10-24-2011 12:20 AM

Have we consulted the sanitation department on this yet?

BIGTYMER 10-24-2011 12:26 AM

Quote:

Originally Posted by V_RocKs (Post 18511207)
Have we consulted the sanitation department on this yet?

As long as product isn't a user submitted variable he's good.


All times are GMT -7. The time now is 11:33 AM.

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