Build you country combo options from the country table. The value for each option should be the id/code for the country
Here's an example
<?php
$res = $db->query("SELECT customer_id
, fname
, lname
, country
FROM customer
LIMIT 10
");
$tdata = '';
foreach ($res as $row) {
$tdata .= "<tr>
<td>{$row['fname']} {$row['lname']}</td>
<td style='text-align: center;'><select name='country'>" . countryOptions($db, $row['country']) . "</select><td>
</tr>";
}
function countryOptions(PDO $db, $current)
{
$opts = "<option value=''>- select country -</option>\n";
$res = $db->query("SELECT country_id as id
, country_name as name
FROM country
ORDER BY name
");
foreach ($res as $row) {
$sel = $row['id'] == $current ? 'selected' : '';
$opts .= "<option $sel value='{$row['id']}'>{$row['name']}</option>\n";
}
return $opts;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
</head>
<body>
<table style='width: 600px;'>
<tr><th>Name</th><th>Country</th></tr>
<?=$tdata?>
</table>
</body>
</html>
Example data and ouput
Table: customer Table: country
+-------------+----------+-----------+---------+ +------------+--------------+
| customer_id | fname | lname | country | | country_id | country_name |
+-------------+----------+-----------+---------+ +------------+--------------+
| 1 | Wanda | Denning | 1 | | 1 | England |
| 2 | Tom | Westbrook | 2 | | 2 | Scotland |
| 3 | Georgina | Jones | 3 | | 3 | Wales |
| 4 | Hannah | Wentworth | 1 | | 4 | N. Ireland |
| 5 | Roy | Egon | 4 | +------------+--------------+
| 6 | Len | Elridge | 1 |
| 7 | Sam | Patterson | 2 |
| 8 | Charles | Knight | 1 |
| 9 | Gerald | Watts | 1 |
| 10 | Tom | Bowles | 4 |
+-------------+----------+-----------+---------+