我有一个主类Employee,它获取Employees Details,Passed Inputs获取mysql结果,并返回到一个关联数组到$ row。
public function Result(){
$this->IsEmptyCheck();
$this->ConnectDb();
$this->QueryDb();
$this->RowCount();
$this->IfEmployeeFound();
}
public function IfEmployeeFound(){
if ($this->row_cnt > 0)
{
while ($row = $this->result->fetch_assoc()){
return($row);
}
}else{echo "No Results" ;}
}
public function CustomhtmlTabledisplay($row){
foreach ( $row as $key => $value ) {
echo .....
echo "<td>".$value['employee_name']."</td>\n";
echo "<td>".$value['age']."</td>\n";
echo "<td>".$value['familydetails']."</td>\n";
echo .....
}
}
我正在运行下面的php调用,调用employee类并在其中执行上面的函数。
$check = new Employee($employeeid);
$check->Result()->CustomhtmlTabledisplay();
$check->CloseDb();
我想通过传递mysql返回的行数组来获取数据 IfEmployeeFound()进入 CustomhtmlTabledisplay();
我想通过执行此类查询来显示员工详细信息 的 $入住&GT;结果() - &GT; CustomhtmlTabledisplay();
答案 0 :(得分:1)
(如果我明白的话)。做下一步 - by executing this type of query
:
$check->Result()->CustomhtmlTabledisplay();
在链接方法的每个方法的末尾都需要return $this
。并且需要将数据存储在主类的property
- 字段中。
修改强>
如果你想像你这样使用你的课程
$check->CustomhtmlTabledisplay(($check->Result());
将类方法更改为:
public function Result(){
$this->IsEmptyCheck();
$this->ConnectDb();
$this->QueryDb();
$this->RowCount();
return $this->IfEmployeeFound();
}
public function IfEmployeeFound(){
$out = array();
if ($this->row_cnt > 0){
while ($row = $this->result->fetch_assoc())
$out[] = $row;
}
return empty($out)? null: $out;
}
public function CustomhtmlTabledisplay($rows){
if($rows){
foreach ( $rows as $row) {
echo .....
echo "<td>".$row['employee_name']."</td>\n";
echo "<td>".$row['age']."</td>\n";
echo "<td>".$row['familydetails']."</td>\n";
echo .....
}
}
}
答案 1 :(得分:0)
您可以使用
require_once (employee.php); //employee is the file where you have the methods
并为班级员工提供实例