Hiding Empty Rows with PHP

Hi There,

I am using a php script to output information about hockey players and I have a couple rows that don’t always have data so are empty. They are below, they are Draft Year: Draft Position: and Drafted Year: I want for them to not appear on players who don’t have these fields filled. Thanks!

[php]Print “

”;
Print “

”.$row[‘FirstName’]." “.$row[‘LastName’].” <img src=“http://www.cnghl.org/cnghldb/nation/".$row[‘NationID’].".gif”>

";
Print “”;
Print “”;
Print “ Birthdate: “.$row[‘DOB’].””;
$DOB = $row[DOB]; //dd.mm.yyyy
$user_date = new DateTime($DOB);
$curr_date = new DateTime();
$age_cal = $curr_date->diff($user_date);
Print “ Age: “.$age_cal->y;””;
Print "<td style='vertical-align:top;'width=‘275’ rowspan=‘10’>
<img src="http://www.cnghl.org/cnghldb/images/".$iPlayerID.".jpg">";
Print “
”;
Print “”;
Print “ Nation: “.$row[‘Nation’].””;
Print " CNGHL Team: ".$row[‘CNGHLRights’]. “”;
Print “”;
Print “”;
Print " Position: ".$row[‘Position’]. “”;
Print " Weight: ".$row[‘Weight’]. “”;
Print “”;
Print “”;
Print " Height: ".$row[‘Height’]. “”;
Print " NHL Team: ".$row[‘Team’]. “”;
Print “”;
Print “”;
Print “ Draft Year: “.$row[‘CNDraftYR’].””;
Print “ Draft Position: “.$row[‘CNDraftPOS’].””;
Print “”;
Print “”;
Print “ Drafted By: “.$row[‘DrTeam’].””;
Print " ";
Print “”;
Print
"

 [/php]

At line 25 you want an if statement that checks for content in your variables, if there is content then execute current lines 25 to 28 if not then go to current line 29.

I am still pretty new at this, how would that look? I am not that familiar with if statement other then in Excel.

Thanks

You probably want something like

[php]
if (! $row[‘CNDraftYR’]==""){
Print “

”;
Print “ Draft Year: “.$row[‘CNDraftYR’].””;
Print “ Draft Position: “.$row[‘CNDraftPOS’].””;
Print “”;
}
[/php]

This is untested and so may not work.

See http://www.tizag.com/phpT/if.php for a tutorial.

Thanks that did the trick! Much appreciated

Sponsor our Newsletter | Privacy Policy | Terms of Service