我将表中某一行的属性列表回显到用户选择的选项列表中,以便稍后用于插入到另一列表中表。我试图做的是,为了存储该行的'id' - 不单独使用外键,而是保存的'id'是列表中最后一行的'id'。下面是一个片段,以我的代码:在mysql选项选择列表中存储行的标识
<?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>
你正在覆盖'$ _SESSION ['thisId']'循环的每一次迭代。这样做,你将永远结束最后一个。 –
如果你想要选择的ID,只需使用'$ _SESSION [“thisId”] ='$ _POST ['list']' – Barmar
你必须在数组中包含'{}',而不是'$ thisRegion' 。数组的关键字必须在引号之间:'$ row ['streetAddress']' –