Spouse or no spouse?

So I have a table to hold info of people registering for an event. It includes fields for firstname, lastname and spousename. When I create a page to see details I want to show
Jane Doe (if Jane is single)
John & Jane Doe (if they are a couple)

The obvious problem is if I echo the first, spouse, and last names like so:

<?php echo $row_rs_details['firstname'] . ' & ' .  $row_rs_details['spousename'] . " " . $row_rs_details['lastname']; ?>

and there is no spouse I’ll get
Jane & Doe

How do I show spouse only if there is one?


<?php
printf(
  '&#37;s %s %s',
  $row_rs_details['firstname'],
  false === empty($row_rs_details['spousename']) ? '&amp; ' . $row_rs_details['spousename'] : '',
  $row_rs_details['lastname']
);
?>

Perfect! Thanks so much :smiley: