简体   繁体   中英

Select Option PHP

I am implementing some code but for some reason when I choose an option it retrieves correctly the row I want but I can't select the "Select" to show all the results again.

For example, I have "SELECT", "A", "B". When I choose A or B it shows me the A or B results but when I want it to show all clicking "SELECT" it shows me the last result.

EDIT: And when I choose an option, the option stays "SELECT" and not the one I selected...

The code is:

        <td class="titletable2" >GRUPO<font color="#F25C09">: </font></td>
<td>
    <select name="grupo_id_grupo" id="id_grupo" onchange="document.getElementById('pesquisaform').submit()">
        <option value="-1" 
        <?php if ($_SESSION["filtro"]['id_'] == '-1' || !isset($_SESSION["filtro"]['grupo_id_grupo'])) { echo "selected"; } ?>>
        <?php echo "<option value = '".$grupo['nome']."'";?></option>
        <?php 
            $DB = new DataBase();
            $listagrupos = $DB->select_associative_data("grupo", "*");
            $DB->disconnect();

             foreach ($listagrupos as $grupo){
                echo "<option value = '".$grupo['id_grupo']."'";

                if( isset($_SESSION["filtro"]['id_grupo']) && $_SESSION["filtro"]['id_grupo'] == $grupo['id_grupo']){ echo "selected";};

                echo ">".$grupo['nome']."</option>";
            }
        ?>
    </select>
</td>
$DB = new DataBase();

                $listagrupos = $DB->query(SELECT * FROM grupo);

                $DB->disconnect();

i think you need query or queryFunc instead of select_associative_data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM