$r = mysql_query($con, 'SELECT patients.*, IF(grouped_priem.card_id IS NULL, 0, 1) AS has_priem FROM patients LEFT JOIN (SELECT card_id FROM priem GROUP BY card_id) AS grouped_priem ON patients.card_id = grouped_priem.card_id');
<?php while($row = mysqli_fetch_assoc( $r )): ?>
<tr bgcolor="<?php echo $row['has_priem'] ? '#ffffff' : '#ffff99' ?>">
<td><a href="view_patient.php?id=<?php echo $row['card_id']; ?>"><?php echo (" ".$row["card_id"]." "); ?></a></td>
<td><a href="view_patient.php?id=<?php echo $row['card_id']; ?>"><?php echo (" ".$row["fio"]." "); ?></a></td>
<td><a href="view_patient.php?id=<?php echo $row['card_id']; ?>"><?php echo (" ".$row["adress"]." "); ?></a></td>
<td><a href="view_patient.php?id=<?php echo $row['card_id']; ?>"><?php echo (" ".$row["phone"]." "); ?></a></td>
<td><a href="view_patient.php?id=<?php echo $row['card_id']; ?>">Посмотреть</a></td>
<td><a href="del_patient.php?id=<?php echo $row['card_id']; ?>">Удалить</a><td>
</tr>
<?php endwhile; ?>