Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74735

Retriving database data from dropdown menu and printing in page

$
0
0

I have a problem printing values of multiple selected tables.

I have in an index page a dropdown menu which is filled with companies names, I want to use that dropdown menu and select all the information of employers and employees and print in the same index page.

I show what I've got so far, I tried multiple things but I can not get the grip of it.

<?php
        $link = mysqli_connect('localhost', 'root', '', 'providecodb');
        $resultSet = mysqli_query($link, "SELECT empresa FROM contratistas");
        $color1 = "lightblue";
        $color2 = "teal";
        $color = "$color1";
        ?>
        <select name="empresas">
            <option value="blank" style="background:lightblue"></option>
        <?php
        while($rows = $resultSet->fetch_assoc())
        {
            $color == $color1 ? $color = $color2 : $color = $color1;
            $empresa = $rows[empresa];
            echo "<option value='$empresa' style='background:$color'>$empresa</option>";
        }
        mysqli_close($link);
        ?>
    </select> Empresa
    </div>

        <div class="column2" align="right">
            <?php
                if(!isset($_POST['empresa'])){
                    echo "<b>Información de contratistas:</b>";
                }else{
                    mysqli_connect('localhost', 'root', '', 'providecodb');
                    $sql1 = "SELECT * FROM contratistas WHERE empresa='{$_POST['$empresa']}'";
                    $sql2 = "SELECT * FROM empleados WHERE empresa='{$_POST['$empresa']}'";

                    $result1 = mysqli_query($link,$sql1);
                    $result2 = mysqli_query($link,$sql2);

                    $row1 = mysqli_fetch_assoc($result1);
                    $row2 = mysqli_fetch_assoc($result2);

                    echo $row1(['nombre']);
                    echo $row1(['dni']);
                    echo $row1(['telefono']);
                    echo $row2(['nombre']);
                    echo $row2(['dni']);
                    echo $row2(['telefono']);


                    }


            ?>

Can you give me hints on what's my problem so I can proceed with it?


Viewing all articles
Browse latest Browse all 74735

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>