0
我正在運行以下命令以從我的MySQL數據庫中獲取類型標識和名稱。應顯示兩個結果。在選擇列表中顯示兩個選項,但id或name不存在,它們只在頁面上顯示爲空白。PHP和MySQL獲取選擇值
function get_category_selector($form_name) {
if (isset($_SESSION['loggedin']['cur_category'])) {
$curr = $_SESSION['loggedin']['cur_category'];
} else {
$curr = -1;
}
$rtn = "";
$rtn .= '<select id="category" name="category">';
$rtn .= '<option value="-1"';
if ($curr == -1) {
$rtn .= ' selected';
}
$rtn .= '>Select a Category</option>';
$DB = new mysql_db();
$DB->sql_connect();
$q = "SELECT DISTINCT (categories.categories_id), categories.categories_name FROM categories LEFT JOIN prod2cat ON prod2cat.prod2cat_cat = categories.categories_id LEFT JOIN products ON prod2cat.prod2cat_product = products.products_id LEFT JOIN prod2type ON products_id = prod2_product LEFT JOIN type ON prod2_type = type_id WHERE type.type_id =2 order by categories.categories_name asc";
$DB->query($q);
if ($DB->get_num_rows()) {
$results = $DB->fetch_all_rows(MYSQL_ASSOC, NULL);
foreach ($results as $key => $row) {
$rtn .= '<option value="' . $row['Categories_ID'] . '"';
if ($curr == $row['Categories_ID']) {
$rtn .= ' selected';
}
$rtn .= '>' . trim($row['Categories_Name']) . '</option>';
}
}
$rtn .= '</select>';
return $rtn;
}
變化以小寫'$ row ['categories_id']'&&'$ row ['categories_name']' – Cyclonecode
什麼是mysql_db分類S'請告訴我們這是如何工作的(發佈類定義),謝謝。 〜雷 –