我正在运行以下命令以从我的 MySQL 数据库中获取类型 ID 和名称。应显示两个结果。选择列表中显示了两个选项,但不存在 id 或 name,它们仅在页面上显示为空白。
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;
}