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

140
Visualizações
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 Respostas
Responde à pergunta

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 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