I have a form on a Wordpress page posting data to a table called 'members'. I have a second page displaying this data in a table. All is working well. The data is being displayed using:
$myrows = $wpdb->get_results( "SELECT first_name, surname, role, email, country, bio FROM members" );
foreach ( $myrows as $row ) {
echo "<tr><td>" . $row->first_name . "</td><td>" . $row->surname . "</td><td>" . $row->role . "</td><td>" . $row->email . "</td><td>" . $row->country . "</td></tr>";
}
Not all members will have bio's but what I would like to do is say "if the member has a bio, make the first name clickable to display a pop-up containing the bio."
So my question is how do I add an IF statement inside an echo as above?
Would it be easier to split the echo statement as below?
echo '<tr><td>';
if($row->bio) {
echo '<a href="#">' . $row->first_name . '</a>';
echo '<div class="bio" style="display: none;">' . $row->bio . '</div></td><td>';
} else {
echo $row->first_name;
echo '</td><td>';
}
echo $row->surname;
echo '</td><td>';
echo $row->role;
echo '</td><td>';
echo $row->email;
echo '</td><td>';
echo $row->country;
echo '</td></tr>';
Thanks, Adrian