Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!