在 class 中设置下拉菜单的 ID
Set the id of a drop-down within a class
我正在尝试使用 class 为输入字段生成下拉列表。下拉列表有效并已填充,但是我正在尝试查找如何从传递给 class 的变量中设置 id 的文档。原因是下拉框要用在各种形式的不同位置,所以我希望这样设置id。
<?php
class ddUsers {
public $dfID;
function set_id($dfID) {
$this->id = $dfID;
}
function getField() {
// query code is here, standard select with mysqli //
?>
<select class ="inline" id ='How to get the ID in here?' name = "UUID" value = "">
<option> // query results via for loop go here // </option>
调用 class 有效:
$field = new ddUsers();
$field->set_id(17);
$field->getField();
我用简单的 echo $this->id
解决了这个问题,因为 <select>
代码在函数中:
<select class ='inline' id ='<?php echo $this->id; ?>' name = 'UUID' value = ''>
<option>Please select a user:</option>"
“查看源代码”的结果是:
<select class ='inline' id ='17' name = 'UUID' value = ''>
<option>Please select a user:</option>"
<option value=2>Username1</option><option value=1>Username2</option></select>
我正在尝试使用 class 为输入字段生成下拉列表。下拉列表有效并已填充,但是我正在尝试查找如何从传递给 class 的变量中设置 id 的文档。原因是下拉框要用在各种形式的不同位置,所以我希望这样设置id。
<?php
class ddUsers {
public $dfID;
function set_id($dfID) {
$this->id = $dfID;
}
function getField() {
// query code is here, standard select with mysqli //
?>
<select class ="inline" id ='How to get the ID in here?' name = "UUID" value = "">
<option> // query results via for loop go here // </option>
调用 class 有效:
$field = new ddUsers();
$field->set_id(17);
$field->getField();
我用简单的 echo $this->id
解决了这个问题,因为 <select>
代码在函数中:
<select class ='inline' id ='<?php echo $this->id; ?>' name = 'UUID' value = ''>
<option>Please select a user:</option>"
“查看源代码”的结果是:
<select class ='inline' id ='17' name = 'UUID' value = ''>
<option>Please select a user:</option>"
<option value=2>Username1</option><option value=1>Username2</option></select>