Populate a Drop down box from a mySQL table in PHP

后端 未结 7 773
温柔的废话
温柔的废话 2020-11-27 05:40

I am trying to populate a Drop down box from results of a mySQL Query, in Php. I\'ve looked up examples online and I\'ve tried them on my webpage, but for some reason they j

相关标签:
7条回答
  • 2020-11-27 06:09

    After a while of research and disappointments....I was able to make this up

         <?php $conn = new mysqli('hostname', 'username', 'password','dbname') or die ('Cannot connect to db') $result = $conn->query("select * from table");?>
    
    //insert the below code in the body
    
    
        <table id="myTable"> <tr class="header"> <th style="width:20%;">Name</th>
        <th style="width:20%;">Email</th>
           <th style="width:10%;">City/ Region</th>
            <th style="width:30%;">Details</th>
      </tr>
      <?php
       while ($row = mysqli_fetch_array($result)) {
    
                   echo "<tr>";
                   echo "<td>".$row['username']."</td>";
                   echo "<td>".$row['city']."</td>";
                    echo "<td>".$row['details']."</td>";
                   echo "</tr>";
               }
    
         ?>
    </table>
    

    Trust me it works :)

    0 讨论(0)
提交回复
热议问题