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

前端 未结 7 1131
面向向阳花
面向向阳花 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:24

    What about something like this :

    echo '';
    

    Of course, up to you to decide which items from $row should be used for the value and the text of each


    Just make sure you are escaping the data that comes from your DB -- especially if it can contain HTML ; as you are outputting HTML, this can be done with htmlspecialchars or htmlentities.

    Note that those might take a couple of additionnal parameters that I didn't use in my example -- setting those can be useful, depending on the charset you're using.

提交回复
热议问题