Help with php if statement

I need to add an if !empty conditional to the following code
Which is being echo’d out fine but some of these variables sometimes return null so i need to not display it if the id variables are null ie: $headid $shirtid etc…

".if(!(empty($artist_website) && empty($artist_youtube) && empty($artist_twitter))) :."
<div class=\"wowequip\"><br>Equipped Gear<br><br>
<a href=\"http://www.wowhead.com/item=".$headid."\" rel=\"item=".$headid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$headicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$neckid."\" rel=\"item=".$neckid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$neckicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$shoulderid."\" rel=\"item=".$shoulderid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$shouldericon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$backid."\" rel=\"item=".$backid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$backicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$chestid."\" rel=\"item=".$chestid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$chesticon.".jpg\"></a>
:. if(!empty($shirtid)) { ."<a href=\"http://www.wowhead.com/item=".$shirtid."\" rel=\"item=".$shirtid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$shirticon.".jpg\"></a>".}."
<a href=\"http://www.wowhead.com/item=".$tabardid."\" rel=\"item=".$tabardid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$tabardicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$wristid."\" rel=\"item=".$wristid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$wristicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$handsid."\" rel=\"item=".$handsid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$handsicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$waistid."\" rel=\"item=".$waistid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$waisticon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$legsid."\" rel=\"item=".$legsid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$legsicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$feetid."\" rel=\"item=".$feetid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$feeticon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$finger1id."\" rel=\"item=".$finger1id."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$finger1icon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$finger2id."\" rel=\"item=".$finger2id."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$finger2icon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$trinket1id."\" rel=\"item=".$trinket1id."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$trinket1icon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$trinket2id."\" rel=\"item=".$trinket2id."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$trinket2icon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$mainHandid."\" rel=\"item=".$mainHandid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$mainHandicon.".jpg\"></a>
</div>

".endif;."

sry i tried to edit the other code this is what im using now which doesnt work

".if(!(empty($shirtid) && empty($headid) && empty($backid))) :."
<div class=\"wowequip\"><br>Equipped Gear<br><br>
<a href=\"http://www.wowhead.com/item=".$headid."\" rel=\"item=".$headid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$headicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$neckid."\" rel=\"item=".$neckid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$neckicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$shoulderid."\" rel=\"item=".$shoulderid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$shouldericon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$backid."\" rel=\"item=".$backid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$backicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$chestid."\" rel=\"item=".$chestid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$chesticon.".jpg\"></a>
:. if(!empty($shirtid)) { ."<a href=\"http://www.wowhead.com/item=".$shirtid."\" rel=\"item=".$shirtid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$shirticon.".jpg\"></a>".}."
<a href=\"http://www.wowhead.com/item=".$tabardid."\" rel=\"item=".$tabardid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$tabardicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$wristid."\" rel=\"item=".$wristid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$wristicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$handsid."\" rel=\"item=".$handsid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$handsicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$waistid."\" rel=\"item=".$waistid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$waisticon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$legsid."\" rel=\"item=".$legsid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$legsicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$feetid."\" rel=\"item=".$feetid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$feeticon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$finger1id."\" rel=\"item=".$finger1id."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$finger1icon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$finger2id."\" rel=\"item=".$finger2id."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$finger2icon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$trinket1id."\" rel=\"item=".$trinket1id."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$trinket1icon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$trinket2id."\" rel=\"item=".$trinket2id."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$trinket2icon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$mainHandid."\" rel=\"item=".$mainHandid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$mainHandicon.".jpg\"></a>
</div>

".endif;."

Swap this
[php]".if(!(empty($shirtid) && empty($headid) && empty($neckid))) {."[/php]
With this
[php]".if(!empty($shirtid) && !empty($headid) && !empty($neckid)) {."[/php]

where do i close the endif at the bottom?

".endif;."

i did this a the bottom and still no good…

". } endif;."

maybe you should show the full code from the to the end of it
[php]".} endif;"[/php]

i so appreciate the help but u lost me on that one lol

well there are a few errors in the script but not sure if this is a error or part of code.

[php]rel=“item=.$neckid.’”[/php]
Should it be
[php]rel="" item=’.$neckid.’[/php]

here is the whole source of the script to better understand whats going on

if($vbulletin->userinfo['usergroupid'] == 5 OR $vbulletin->userinfo['usergroupid'] == 6 OR $vbulletin->userinfo['usergroupid'] == 7 OR $vbulletin->userinfo['usergroupid'] == 10 OR $vbulletin->userinfo['usergroupid'] == 2)
{


$json = file_get_contents("http://us.battle.net/api/wow/character/Shattered%20Hand/". $vbulletin->userinfo['username']."?fields=guild,items,professions,reputation,stats,pvp,titles,progression,feed", true);
$decode = json_decode($json, true);
$name = " ". $decode[name] ."";
$realm = " ". $decode[realm] ."";
$ailevel = " ". $decode[items][averageItemLevel] ."";
$aeilevel = " ". $decode[items][averageItemLevelEquipped] ."";
$Thumbnail = "". $decode[thumbnail] ."";
$guild_name = " ". $decode[guild][name] ."";
$achievement = "". $decode[achievementPoints] ."";
$health = "". $decode[stats][health] ."";
$mana = "". $decode[stats][power] ."";
$ilvl = "". $decode[items][averageItemLevelEquipped] ."";
$prof1name = "". $decode[professions][primary][0][name] ."";
$prof2name = "". $decode[professions][primary][1][name] ."";
$hk = $decode[pvp][totalHonorableKills] ."";
$feed = $decode[feed][0] ."";
$title = $decode[title][selected] ."";
$battlegroup = $decode[battlegroup] ."";
$bliziconurl = "http://us.media.blizzard.com/wow/icons/56";
$headid = "". $decode[items][head][id] ."";
$headname = "". $decode[items][head][name] ."";
$headicon = "". $decode[items][head][icon] ."";
$neckid = "". $decode[items][neck][id] ."";
$neckname = "". $decode[items][neck][name] ."";
$neckicon = "". $decode[items][neck][icon] ."";
$shoulderid = "". $decode[items][shoulder][id] ."";
$shouldername = "". $decode[items][shoulder][name] ."";
$shouldericon = "". $decode[items][shoulder][icon] ."";
$backid = "". $decode[items][back][id] ."";
$backname = "". $decode[items][back][name] ."";
$backicon = "". $decode[items][back][icon] ."";
$chestid = "". $decode[items][chest][id] ."";
$chestname = "". $decode[items][chest][name] ."";
$chesticon = "". $decode[items][chest][icon] ."";
$shirtid = "". $decode[items][shirt][id] ."";
$shirtname = "". $decode[items][shirt][name] ."";
$shirticon = "". $decode[items][shirt][icon] ."";
$tabardid = "". $decode[items][tabard][id] ."";
$tabardname = "". $decode[items][tabard][name] ."";
$tabardicon = "". $decode[items][tabard][icon] ."";
$wristid = "". $decode[items][wrist][id] ."";
$wristname = "". $decode[items][wrist][name] ."";
$wristicon = "". $decode[items][wrist][icon] ."";
$handsid = "". $decode[items][hands][id] ."";
$handsname = "". $decode[items][hands][name] ."";
$handsicon = "". $decode[items][hands][icon] ."";
$waistid = "". $decode[items][waist][id] ."";
$waistname = "". $decode[items][waist][name] ."";
$waisticon = "". $decode[items][waist][icon] ."";
$legsid = "". $decode[items][legs][id] ."";
$legsname = "". $decode[items][legs][name] ."";
$legsicon = "". $decode[items][legs][icon] ."";
$feetid = "". $decode[items][feet][id] ."";
$feetname = "". $decode[items][feet][name] ."";
$feeticon = "". $decode[items][feet][icon] ."";
$finger1id = "". $decode[items][finger1][id] ."";
$finger1name = "". $decode[items][finger1][name] ."";
$finger1icon = "". $decode[items][finger1][icon] ."";
$finger2id = "". $decode[items][finger2][id] ."";
$finger2name = "". $decode[items][finger2][name] ."";
$finger2icon = "". $decode[items][finger2][icon] ."";
$trinket1id = "". $decode[items][trinket1][id] ."";
$trinket1name = "". $decode[items][trinket1][name] ."";
$trinket1icon = "". $decode[items][trinket1][icon] ."";
$trinket2id = "". $decode[items][trinket2][id] ."";
$trinket2name = "". $decode[items][trinket2][name] ."";
$trinket2icon = "". $decode[items][trinket2][icon] ."";
$mainHandid = "". $decode[items][mainHand][id] ."";
$mainHandname = "". $decode[items][mainHand][name] ."";
$mainHandicon = "". $decode[items][mainHand][icon] ."";


$shoulderenchant = "". $decode[items][shoulder][tooltipParams][enchant] ."";
$backenchant = "". $decode[items][back][tooltipParams][enchant] ."";
$chestenchant = "". $decode[items][chest][tooltipParams][enchant] ."";
$wristenchant = "". $decode[items][wrist][tooltipParams][enchant] ."";
$handsenchant = "". $decode[items][hands][tooltipParams][enchant] ."";
$legsenchant = "". $decode[items][legs][tooltipParams][enchant] ."";
$feetenchant = "". $decode[items][feet][tooltipParams][enchant] ."";
$finger1enchant = "". $decode[items][finger1][tooltipParams][enchant] ."";
$finger2enchant = "". $decode[items][finger2][tooltipParams][enchant] ."";
$mainHandenchant = "". $decode[items][mainHand][tooltipParams][enchant] ."";




$template_hook['forumhome_above_forums'] .= "<img src=\"http://us.battle.net/static-render/us/".$Thumbnail."\"><div class=\"wowapilayout\">
    <div class=\"th\">
     <div class=\"td\" ><img src=\"http://www.wowpedia.org/images/1/1d/Guild_achievement_icon.png\" width=\"25px\"><span class=\"wowtext\">".$achievement."</span></div>
     <div class=\"td\">Health: <span class=\"wowtext\">".$health."</div>

     <div class=\"td\">Mana: <span class=\"wowtext\">".$mana."</div>
     <div class=\"td\">Equipped iLvL: <span class=\"wowtext\">". $ilvl ."</div>
     <div style=\"clear: both;\"></div>
    </div>
    <div class=\"tr\">
     <div class=\"td\">".$prof1name."</div>
     <div class=\"td\">".$prof2name."</div>
     <div class=\"td\">HK's: <span class=\"wowtext\">$hk</span></div>
     <div class=\"td\">Battlegroup: $battlegroup</div>
     <div style=\"clear: both;\"></div>
    </div>
    <div class=\"tr\">
     <div class=\"td\"></div>
     <div class=\"td\"></div>
     <div class=\"td\"></div>
     <div style=\"clear: both;\"></div>
    </div>
    <div class=\"tr\">
     <div class=\"td\"></div>
     <div class=\"td\"></div>
     <div class=\"td\"></div>
     <div class=\"td\"></div>
     <div style=\"clear: both;\"></div>
    </div>
   </div>
<br>

".if(!empty($shirtid) && !empty($headid) && !empty($neckid)) {."
<div class=\"wowequip\"><br>Equipped Gear<br><br>
<a href=\"http://www.wowhead.com/item=".$headid."\" rel=\"item=".$headid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$headicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$neckid."\" rel=\"item=".$neckid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$neckicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$shoulderid."\" rel=\"item=".$shoulderid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$shouldericon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$backid."\" rel=\"item=".$backid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$backicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$chestid."\" rel=\"item=".$chestid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$chesticon.".jpg\"></a>
". if(!empty($shirtid)) { ."<a href=\"http://www.wowhead.com/item=".$shirtid."\" rel=\"item=".$shirtid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$shirticon.".jpg\"></a>".}."
<a href=\"http://www.wowhead.com/item=".$tabardid."\" rel=\"item=".$tabardid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$tabardicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$wristid."\" rel=\"item=".$wristid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$wristicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$handsid."\" rel=\"item=".$handsid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$handsicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$waistid."\" rel=\"item=".$waistid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$waisticon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$legsid."\" rel=\"item=".$legsid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$legsicon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$feetid."\" rel=\"item=".$feetid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$feeticon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$finger1id."\" rel=\"item=".$finger1id."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$finger1icon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$finger2id."\" rel=\"item=".$finger2id."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$finger2icon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$trinket1id."\" rel=\"item=".$trinket1id."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$trinket1icon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$trinket2id."\" rel=\"item=".$trinket2id."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$trinket2icon.".jpg\"></a>
<a href=\"http://www.wowhead.com/item=".$mainHandid."\" rel=\"item=".$mainHandid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$mainHandicon.".jpg\"></a>
</div>

".} endif; ."

     <div class=\"td\"></div>";

}


i just had it working a second ago not sure wtf i did now but that source is how it stands now

no i didnt firefox doesnt show empty img tags lol

could you please help me constuct the code im going mad! thanks again for you help.

why do you have 2

[php]
if(!empty($shirtid) && !empty($headid) && !empty($neckid)) {

if(!empty($shirtid)) {
[/php]

what are you trying to accomplish with that

why wouldnt you do the first one put what you want to show up if all those are empty
then do an else statement to show everything when they are not empty and take the endif off

im a super n00b who has been just putting stuff together as i go along… Ive been teaching myself. well trying to at least. It would be great if someone could write it up for me and show me how its done i really have no idea what im doing here. Thanks again for everyones help.

". if(!empty($shirtid)) { ."<a href=\"http://www.wowhead.com/item=".$shirtid."\" rel=\"item=".$shirtid."\"><img class=\"wowequipimg\" src=\"".$bliziconurl."/".$shirticon.".jpg\"></a>".}."

What im trying to accomplish is if the $neckid is null hide the whole line of code.

Maybe you need to do it another way with ternary operator true / false

[php]


Equipped Gear

( $headid == '' ) ? '' : ' ( $headid == '' ) ? '' : ' ( $shoulderid == '' ) ? '' : ' ( $backid == '' ) ? '' : ' ( $chestid == '' ) ? '' : '

[/php]

I found this example which i would like to build off what i need to know is how to not display if variable is null

so for example


if ($number == NULL) {
echo 'there is a $number';
}
else {
echo 'There is no value';
}

You are trying to echo out an if statement but not sure if this will work, thats why I said to try it the other way and see if the variable is true or false, if true then echo the code out if false or null then echo nothing.

It is the same as if statement.

But you asked for this example below

[php]
$number =""; // the var has no value or null

// query the var to see if its has a value or is null
if ($number == NULL || $number == “”) {
//if the var does not have a value then print this to screen
echo ‘this ‘.$number.’ has no value’;
}else{
//if the var does have a value then print this to screen
echo ‘this ‘.$number.’ has a value’;
}
[/php]

I asked cause i was reading on the other stuff u wrote and i am yet to grasp it this method i understand a bit better thank you for your patience with me! Im so clueless atm hah im going to try it

Sponsor our Newsletter | Privacy Policy | Terms of Service