Php 带有动态下拉菜单的optgroup

Php 带有动态下拉菜单的optgroup,php,mysql,Php,Mysql,大家好,我有下表 -------------------------------------------- |ID|point_name|point_address|point_category| |01|bobs |7362 178 st |House | |02|Greegs |1123 118 Ave |Store | And so on -------------------------------------------- 我想在组合

大家好,我有下表

--------------------------------------------
|ID|point_name|point_address|point_category|
|01|bobs      |7362 178 st  |House         |
|02|Greegs    |1123 118 Ave |Store         |
And so on
--------------------------------------------
我想在组合框上使用optgroup函数,这样用户可以在搜索时得到分类的结果

到目前为止,我的代码是:

<select id="combobox">
<?php
$end_point   = "SELECT * FROM points";
$q_end_point = $conn->query($end_point);
$q_end_point->setFetchMode(PDO::FETCH_BOTH);
while ($row = $q_end_point->fetch()) {
    echo "<option value='" . $row['point_address'] . "'>" . $row['point_name'] . "</option>";
}
?> 

我不知道如何添加optgroup,但是,有人能给我指出正确的方向吗

谢谢



看起来很好,你到底有什么错误?你想分类什么类型?点(u)类别??
 <?php

/* First you need to format your array like bellow*/

$array = array(
    array(
        'category' => "House",
        'result' => array(
            1,
            2,
            3
        )
    ),
    array(
        'category' => "Store",
        'result' => array(
            4,
            5,
            6
        )
    )
);

?>


<select>
    <?php foreach($array as $value): ?>
    <optgroup label="<?php echo $value['category'];?>">
        <?php foreach($value[ 'result'] as $value): ?>
        <option value="<?php echo $value;?>">
            <?php echo $value;?>
        </option>
        <?php endforeach ?>
    </optgroup>
    <?php endforeach ?>
</select>