Populate drop down list from MySQL column data

前端 未结 2 1844
野的像风
野的像风 2021-01-07 07:11

I am currently having trouble displaying the entries in a column of my database in a drop down list.

The code below... is half working i guess... When I run it, the

相关标签:
2条回答
  • 2021-01-07 07:24

    { is not needed inside <option>

    echo "<option>".$row['teamname']."</option>"
    
    0 讨论(0)
  •  <select id="teamlist" name="teamlist">
     <?php
            $pdo = new PDO('mysql:host=localhost;dbname=clubresults', 'root', '12345678');
            #Set Error Mode to ERRMODE_EXCEPTION.
            $pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);  
    
        $stmt = $pdo->prepare('Select teamname from members');
        $stmt->execute();
           while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        echo '<option>'.$row['teamname'].'</option>';
           }
         ?>
     </select> 
    
    0 讨论(0)
提交回复
热议问题