Using PHP to populate a <select></select>?

前端 未结 7 1134
面向向阳花
面向向阳花 2021-01-11 23:50

I want to populate the above tag with values from database.

I have written php code up to t

相关标签:
7条回答
  • 2021-01-12 00:33

    You can see whats available to use by doing this in the while:

    var_dump($result);
    exit;
    

    That will print the first result and its array contents. Then you can see what field you want to use to populate the option. From there, you would do something like:

    foreach ($result['field'] as $field) {
       print '<option value="'.$field.'">$field</option>';
    }
    

    Of course this is a very basic example, and as others have noted you may want to clean the data before putting it into a form.

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