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

134
Vistas
When <option>"anyTableName"</option> is selected -> show column names of this table (PHP,MySQL=

i am new to stackoverflow, so correct me if i am talking nonsense ;)

My Problem: I´ve got a text.php where 2 are. In the first i select a table (like "accounts", "customers", and so on). The second shows the column names of the selected table. The page should not refresh when the first changes! What i´ve done so far: I managed to get a connection to the MySQL Database (xampp if this is important idk). The tables show up in the first . So howcan i achieve that the column names show up in the 2nd ? I heard of AJAX, JQuery but i dont know anything about it.

'index.php'
<form>
    <div>
    <?php
        //connection ($link is included in the <head>)
        if (!$link) {
            die("Connection failed: " . mysqli_connect_error());
            }
        //SQL-Statement and Query
        $sql1 = "SELECT * FROM tables";
        $result = mysqli_query($link, $sql1);
        ?>
        <select name="tableselect" id="tableselect" size="10">
            <?php
            if (mysqli_num_rows($result) > 0) {
                while($row = mysqli_fetch_assoc($result)) {
            ?>
            <option><?php echo $row['name']; ?></option>
                <?php }
            }
            ?>
        </select>

//second <select>
        <?PHP

            $sql2 = "SELECT COLUMN_NAME 
            FROM INFORMATION_SCHEMA.COLUMNS 
            WHERE 
                TABLE_SCHEMA = Database()
                AND TABLE_NAME = '$variable' ;";
            $result = mysqli_query($link, $sql2);
            echo $sql2
        ?>
        <select name="fieldnames" id="fieldnames" size="10">
            <option>*</option>
            <?php
                while($row=mysqli_fetch_array($resultf)) {
                ?>
                <option><?php echo $row['COLUMN_NAME']; ?></option>
                <?php }
            ?>
        </select>
        </div>
    </form>

I thought that $variable means that the name of the selected table (from 1st ) must be placed in this variable.

Any help would be nice :) If anything should be styled better let me know :D

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Yes, you achieve this easily by using JQuery Ajax or VueJS/Axios. Check out this tutorial Dynamic Dependent Select Box using jQuery, Ajax and PHP

This is also possible with alpinejs fetch if you don't want to use heavy frameworks.

Check out the answer here. AlpineJS for dynamic select menu

over 4 years ago · Santiago Trujillo 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