我試圖創建簡單的下拉菜單與數字(0,1,2)作爲值。 爲了使啓動更容易,我將選定的值設置爲編號2.沒有出現錯誤, 下拉框存在,但沒有顯示任何值。我究竟做錯了什麼。請幫助下拉菜單在OOP php
<?php
class pulldown {
function setName($name) { $this->name = $name; } // sets name of
//select field
function setSelected($selected) { $this->setSelected=$selected; }
function showSelected() {
printf ("<select name='%s'>", $this->name);
foreach($this->lookupTable as $key => $val)
{
if($this->selected == $key){
echo "<option select='selected' value='$key'>$val</option>";
}else {
echo "<option value='$key'>$val</option>";
}
}
echo" </select>";
}
private $lookupTable;
private $selected;
private $name;
}
//////////////////////////////////////////////////
class numbers extends pulldown {
function __construct() {
$this->setName('numbers');
$this->setSelected("0");
///this are the numbers available to select
$this->lookupTable = Array (
"0" => "zero",
"1" => "one",
"2" => "two"
);
}
}
$mynumbers = new numbers();
$mynumbers->setSelected("2");
//$myresellers = new myresellers();
?>
<html>
<form action="pullDown.php" method="post">
<table width="1000" border="0" align="center">
<td>
<?php $mynumbers->showSelected(); ?>
</td>
</table>
</form>
'$ this-> setSelected = $ selected; private $ selected;'你在那兒有錯誤的變量名。 – scragar