作为一个初学者,我不知道如何在下拉列表中显示枚举。 SQL部分是可以理解的(我认为),但是PHP是不可以的。
我也尝试了其他例子长达4个小时。什么都没有,这就是为什么我要问。我希望有人能给我一个明确的答案,而不仅仅是小费,因为我无法用这个理解小费。我希望有人能给我一个明确的答案,并为我调整代码的最后一部分。谢谢你的时间。调整之后,我想我可以在<option>
标记之内的echo $get_enum_values;
标签内回显该函数,或者它如何工作?
这是我的SQL代码:
CREATE TABLE `reis` (
`reis_code` int(10) NOT NULL,
`bestemming` enum('Spanje','Griekenland','Duitsland','Frankrijk','Italie','Indonesie','Australie','Ijsland') NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Gegevens worden geëxporteerd voor tabel `reis`
--
INSERT INTO `reis` (`reis_code`, `bestemming`) VALUES
(1, 'Spanje'),
(2, 'Griekenland'),
(3, 'Duitsland'),
(4, 'Frankrijk'),
(5, 'Italie'),
(6, 'Indonesie'),
(7, 'Australie'),
(8, 'Ijsland');
COMMIT;
这是我与数据库代码的关联:
<?php
// server info
$server = 'localhost';
$user = 'root';
$pass = '';
$db = 'reisbureau';
// connect to the database
$mysqli = new mysqli($server, $user, $pass, $db);
// show errors (remove this line if on a live site)
mysqli_report(MYSQLI_REPORT_ERROR);
?>
这是我在网上找到的代码,由于我对PHP缺乏了解,因此不知道如何调整:
function get_enum_values($connection, $table, $field )
{
$query = "SELECT bestemming from reis ";
$result = mysqli_query($connection, $query );
$row = mysqli_fetch_array($result , MYSQL_NUM );
#extract the values
#the values are enclosed in single quotes
#and separated by commas
$regex = "/'(.*?)'/";
preg_match_all( $regex , $row[1], $enum_array );
$enum_fields = $enum_array[1];
return( $enum_fields );
}