Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

265
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda