Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

264
Visualizações
how do I fetch my data from database in select dropdown list

I am trying to build a Bingo game, where I want to display my previous records in a select(dropdown)!! how do I fetch my data from database in select dropdown list ---below is my php file

           <html>
            <style>
                #rec_mode{
                    background-image: url('register.png');
                    background-size: 100% 100%;
                    width: 100px;
                    height: 50px;
                    border: none;
                    outline: 0px;
                    -webkit-appearance: none;  
                }
            </style>
            <body>
                <select name = "select_history" id="rec_mode">
                    <option selected="true" disabled="disabled">
                    <?php

                        require_once 'config.php';

                        // $hist = mysqli_query($mysqli, "SELECT name FROM `movie_names` ORDER BY movieID DESC");
                        $hist = mysqli_query($mysqli,"SELECT m.name FROM movie_names m INNER JOIN host_table ht WHERE m.movieID = ht.random_num ORDER BY ID DESC");
                        while ($row = $hist->fetch_assoc())
                        {
                            echo "<option value=\"select_history\">".$row['name']."</option>";
                        }
                    ?>
                    </option>
                </select>
            </body>
            </html>
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Why have you added option end tag after php code. Isn't it supposed to be like this.

<select name = "select_history" id="rec_mode">
    <option selected="true" disabled="disabled">Select Option</option>
    <?php
       require_once 'config.php';
       $hist = mysqli_query($mysqli,"SELECT m.name FROM movie_names m INNER JOIN host_table ht WHERE m.movieID = ht.random_num ORDER BY ID DESC");
       while ($row = $hist->fetch_assoc()){
               echo "<option value=\"select_history\">".$row['name']."</option>";
        }
    ?>
</select>
about 4 years ago · Juan Pablo Isaza Relatório

0

First select old selected name from DB eg "harry potter" then use if condition to select inside while loop selected for old one

    $hist = mysqli_query($mysqli,"SELECT m.name FROM movie_names m INNER JOIN 
host_table ht WHERE m.movieID = ht.random_num ORDER BY ID DESC");
$Bingo = "harry potter"; // previously selected value 
                        while ($row = $hist->fetch_assoc())
                        {
                            $selected = "";
                            if($row["name"]==$Bingo) $selected = "selected"; // If you given Id use colunm name id
                            echo "<option value=\"select_history\" $selected >".$row['name']."</option>";
                        }

Thank You

about 4 years ago · Juan Pablo Isaza Relatório

0

First, you have to close that first option tag properly. Also, you might want the option value would be the id column from the db. Please use the correct column names from your tables. But it should be something like this:

<select name = "select_history" id="rec_mode">
<option selected="true" disabled="disabled"> -- SELECT -- </option>  <!-- close it here -->
<?php
    require_once 'config.php';

    $hist = mysqli_query($mysqli,"SELECT m.movieID, m.name FROM movie_names m INNER JOIN host_table ht WHERE m.movieID = ht.random_num ORDER BY movieID DESC"); // make sure query is correct, test it in your mysql client
    while ($row = $hist->fetch_assoc())
    {
        echo "<option value='{$row['movieID']}'>{$row['name']}</option>";
    }
?>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda