我有一个使用 PHP 构建的选项组。一切都很好,直到我不得不获取 DetailID 而不是 DetailName 的值来查找记录。我仍然需要显示 DetailName 但不需要显示 DetailID,我需要将 DetailID 添加到此。我该怎么做?
<?php
include("config.php");
$sql = "SELECT DetailType AS type, DetailID, GROUP_CONCAT(DISTINCT DetailName
ORDER BY DetailName ASC
SEPARATOR '|') AS DetailName FROM tblDetails GROUP BY DetailType";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
echo "<optgroup label='{$row['type']}'>";
$DetailNames = explode('|', $row['DetailName']);
foreach($DetailNames as $DetailName) {
echo '<option value='.$DetailID.'>'.$DetailName.'</option>';
}
echo "</optgroup>";
}
?>
表。tblLocDet LocationID 1,1,2,3 DetailID 1,2,3,4
tblDetails DetailType Feature, Meal Period, Service, Type DetailID 1,2,3,4 DetailName Buffet, Fireplace, WiFi, Waterfront