mardi 5 juillet 2016

Retrieve data from database to selected box with php - bootstrap style

I designed a form with bootstrap and I want to retrieve data from database to a select box. I tried this code:

<div class="form-group"><label class="col-sm-2 control-label">Location</label>

    <div class="col-sm-8"><select class="form-control m-b" name=Location>
        <?php
        $mysqli = new mysqli( 'localhost', 'cshrnaf_user2', '=cXlIBsdMkdr', 'cshrnaf_mis_db' );
        /* check connection */
        if (mysqli_connect_errno())
            {
            printf("Connect failed: %sn", mysqli_connect_error());
            exit();
            }
            $query = "SELECT * FROM adhoc";
            $result = mysqli_query($mysqli,$query);
            while($rows = mysqli_fetch_assoc($result))
            {
              echo "<option value=" . $rows['Aim'] . "></option>";
            }
        ?> 
    </select>
    </div>
</div>

Now it retrieves data in selected box from database like I have 2 rows; it shows 2 options but a blank option like no text.

Aucun commentaire:

Enregistrer un commentaire