下面的代碼是從完美的工作下拉列表中獲取的,然後當我將它放入一個函數中時,它就會破壞它!我在這裏做錯了什麼?在PHP函數中檢索記錄
<?php
require "connect.php";
//create country lists
function records() {
$countryOptions = '';
$query = "SELECT DISTINCT country FROM regions";
$result = mysql_query($query);
if (!$result) {
$countryOptions = "<option>Error Retrieving Records</option>\n";;
}
else {
while ($row=mysql_fetch_assoc($result)) {
$countryOptions .= "<option value=\"{$row['country']}\">";
$countryOptions .= "{$row['country']}";
$countryOptions .= "</option>\n";
}
}
}
echo records();
?>
你沒有從函數返回任何東西 - '$ countryOptions'將會丟失 – 2011-04-30 22:22:38
';;'第11行中確實沒有必要;) – Wh1T3h4Ck5 2011-04-30 22:31:15