Conditional Printing of a link

Afternoon, all - I was hoping I could get some help with an element of my PHP page.

Background: It’s the website for a college athletic department, and we’re refitting after five years to have individual biography pages linked through the roster pages. The staff directory does what we want to do, but since its columns are static (the roster columns for each sport can be adjusted according to what the coaches wish to display), we can simply copy and paste.

Here’s the code snippet from the roster display page:

       if ( $roster_fields != "" && is_array($roster_fields) )
        {
            if ( in_array( "Number", $roster_fields ) ) { print "<td class="".$class."">".$row['Number']."</td>"; }
            print "<td class="".$class."">".FormatName($row['fname'],$row['lname'])."</td>";
            if ( in_array( "Position", $roster_fields ) ) { print "<td class="".$class."">".$row['Position']."</td>"; }
            if ( in_array( "Class", $roster_fields ) ) { print "<td class="".$class."">".$row['Class']."</td>"; }
            if ( in_array( "B_T", $roster_fields ) ) { print "<td class="".$class."">".$row['B_T']."</td>"; }
            if ( in_array( "Event", $roster_fields ) ) { print "<td class="".$class."">".$row['Event']."</td>"; }
            if ( in_array( "Height", $roster_fields ) ) { print "<td class="".$class."">".FormatHeight($row['Height'])."</td>"; }
            if ( in_array( "Weight", $roster_fields ) ) { print "<td class="".$class."">".FormatWeight($row['Weight'])."</td>"; }
            if ( in_array( "Hometown", $roster_fields ) ) { print "<td class="".$class."">".$row['Hometown']."</td>"; }
            if ( in_array( "High_School", $roster_fields ) ) { print "<td class="".$class."">".$row['High_School']."</td>"; }
            if ( in_array( "Club", $roster_fields ) ) { print "<td class="".$class."">".$row['Club']."</td>"; }
        }
        else
        {
            print "<td class="".$class."">".FormatName($row['fname'],$row['lname'])."</td>";
        }

What would be the correct syntax for the fourth line to print a link wrapper around the name if a link has been associated with that record in the database? The name of the link field in the roster table is “link”, and for comparison, here is the code from the staff display page.

<td class="staff"><?php if ( $row['link'] != "" ) { print "<a href="".$row['link']."">"; } ?><?php print FormatName($row['fname'],$row['lname']); ?><?php if ( $row['link'] != "" ) { print "</a>"; } ?>&nbsp;</td>

Any help would be greatly appreciated.

–Skip

Not sure what you are asking for. What do you mean by a link wrapper?

You can basically use the exact same thing:

print "<td class="".$class."">";
$formattedName = FormatName($row['fname'],$row['lname']);
if ( $row['link'] != "" ) { print "<a href="".$row['link']."">".$formattedName."</a>"; }
print "</td>";
Sponsor our Newsletter | Privacy Policy | Terms of Service