我正在做一个 php 工作日历项目。这就是我想要做的:查询数据库并获取计划信息(我得到的那部分),获取该信息并根据每个记录集创建一个工作对象,然后我需要按部门和开始日期对对象进行排序/time,然后根据部门和时间将它们显示在动态表中。我已经做到了这一点:
<?php
session_start();
include_once("functions.php");
class jobs
{
//a job has a:
private $eachJob;
private $group;
private $jID;
private $num;
private $jStatus;
private $description;
private $startDate;
private $endDate;
private $startTime;
private $endTime;
private $rSpan;
private $department;
public function __construct()
{
$this->buildJob($_SESSION['dept']);
}
public function buildJob($depatment)
{
$captionHeading = 'Traditional Print';
$conn = connect();
$tsql = "select + 'Job# ' + CAST (JobNum AS VARCHAR(10)) as JobNum, Description, datediff(MI,StartTime, EndTime) / 15 as 'RowSpan', AssetName,
AssetID, Status.ColorCode as tdCC, JobID, StartTime, EndTime, datediff(day,getDate(),StartTime)*24*60/15 as 'Blank', getdate() as now
from Calendar_View, Departments, Status, Assets
where Departments.DepartmentName = '$depatment' and Calendar_View.Department = Departments.DepartmentID and AssetStatus = Status.StatusID and
Calendar_View.Asset = Assets.AssetID
order by AssetID asc";
$stmt = sqlsrv_query($conn, $tsql);
if ($stmt)
{
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) )
{
/*******************************
$this->jobDetails = array(
$this->group = $row{'AssetName'},
$this->jID = $row['JobID'],
$this->num = $row['JobNum'],
$this->jStatus = $row['tdCC'],
$this->description = "now =" . date_format($row['now'],'Y-m-d'),
$this->startDate = date_format($row['StartTime'],'Y-m-d'),
$this->endDate = date_format($row['EndTime'],'Y-m-d'),
$this->startTime = date_format($row['StartTime'],'g:i'),
$this->endTime = date_format($row['EndTime'],'g:i'),
$this->rspan = "Time needed: " . $row['RowSpan']);
$this->jobInfo($this->jobDetails);
**********************************/
$this->group = $row{'AssetName'};
$this->jID = $row['JobID'];
$this->num = $row['JobNum'];
$this->jStatus = $row['tdCC'];
$this->description = "now =" . date_format($row['now'],'Y-m-d');
$this->startDate = date_format($row['StartTime'],'Y-m-d');
$this->endDate = date_format($row['EndTime'],'Y-m-d');
$this->startTime = date_format($row['StartTime'],'g:i');
$this->endTime = date_format($row['EndTime'],'g:i');
$this->rspan = "Time needed: " . $row['RowSpan'];
//$this->jobInfo();
}
}
else
{
die( print_r(sqlsrv_errors(), true));
}
}
public function jobInfo()
{
}
}
/******************************
class job
{
}
******************************/
?>
我可以通过以下方式访问该作业并从另一个页面执行此操作:
include_once("../php/job_class.php");
$obj=new job("Traditional Print");
echo "<pre>";
echo print_r($obj);
echo "</pre>";
这只给了我从 sql 调用创建的对象。我曾尝试将它放入一个数组并将其传递给 jobinfo 函数,但这给了我一个数组数组并且使处理变得一团糟。我怎样才能完成我想做的事情?