在PHP项目中,我需要列出MySql数据库表中的项目。我使用数据访问类来创建一个Actor对象数组并将其返回到html page& loop Object Array列出下拉列表中的Actors。下面给出的代码不会产生任何恐怖,但它不会列出演员。 (我认为问题出在HTML页面的Array循环中。)请帮我修复这段代码......
数据访问(ActorDA.php)
function SelectAll(){
$oDb = new db;
$result = $oDb->Query('SELECT Id, Name from actor WHERE IsActive=1 ORDER BY Name');
$result_array = array();
while($row = $result->fetch_assoc())
{
$oActor = new Actor();
$oActor->ActorId = $row['Id'];
$oActor->Name = $row['Name'];
$result_array[] = $oActor;
}
return $result_array;
}
商业逻辑(Actor.php)
include_once DATAACCESS . 'ActorDA.php';
Class Actor
{
public $ActorId;
public $Name;
public function GetList()
{
$oActorDA = New ActorDA();
return $oActorDA->SelectAll();
}
HTML页面(ManageActors.php)
require_once CODE . 'Actor.php';
<select name="ddlActor">
<option value="0">Select a Actor</option>
<?php
$arrActors = Actor::GetList();
foreach($arrActors as $actor){
echo '<option value="' . $actor->ActorId . '">'. $actor->Name . '</option>';
}
?>
</select>
答案 0 :(得分:0)
为什么在Actor类中调用$oActionDA->SelectAll()
?这个方法有什么细节吗?
我想你应该拨打$oActionDA->GetList()
那条线。