I'm echoing a list of attributes of a row from a table into an option list for the user to pick from which later would be used to be inserted into another table. What I'm trying to do is, to store the 'id' of that row -not using the foreign key- separately, but the 'id' I keep getting is the 'id' of the last row on the list. Here is a snippet to my code:
<?php
$conn = mysqli_connect('localhost', 'root', '', 'database');
$result = mysqli_query($conn, "SELECT * FROM myTable WHERE region = '{$thisRegion}' ");
//$result .= " ");
while ($row = mysqli_fetch_assoc($result))
{
$selected = (isset($_POST['list']) && $_POST['list'] == $row['id']) ? 'selected' : '';
echo "<option value='$row[streetAddress] $row[apt] $row[city] $row[zip] $row[_state] $row[country]' $selected >$row[city] $row[zip] $row[_state] $row[country] $row[streetAddress] $row[apt]</option>";
$thisId= $row['id'];
$_SESSION["thisId"] = $thisId;
}
?>
</select>