0

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: %s\n", 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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Farhad paikan
  • 89
  • 2
  • 10

1 Answers1

0

Use mysqli_query instead mysql_query and mysqli_fetch_assoc instead mysql_fetch_array

$query = "SELECT * FROM adhoc";
$result = mysqli_query($mysqli,$query);
while($rows = mysqli_fetch_assoc($result))
{
  echo "<option value=" . $rows['Aim'] . "></option>";
}
Brijal Savaliya
  • 1,101
  • 9
  • 19
  • Thanks for you reply, i tried the code, Selected box fetched data, all my entered options are in the Selected box but none of the texts are showing, its all like blank options. I think there might be something wrong with my bootstrap code? – Farhad paikan Jun 17 '16 at 08:20