0
該項目是一個使用PHP的網絡日曆/調度程序。這個想法是,用戶可以安排在特定時間分配給特定機器的作業,其他人可以查看作業計劃和作業分配給的「資產」。然而,調度工作,我不能將數據綁定到他們所屬的頭/列。它看起來像這樣:如何在dymanic表頭中排序和顯示動態數據?
<?php
include_once("HTML/TABLE.PHP");
$data = array( 0=>array(1,'asset1','2013-07-24 10:00:00', '2013-07-24 12:00:00','red',2),
1=>array(2,'asset1','2013-07-24 12:00:00', '2013-07-24 13:00:00','green',3),
2=>array(3,'asset2','2013-07-24 11:00:00', '2013-07-24 12:00:00','blue', 4),
3=>array(4,'asset2','2013-07-24 12:00:00', '2013-07-24 14:00:00','red', 2),
4=>array(5,'asset3','2013-07-24 11:30:00', '2013-07-24 12:00:00','green', 4),
5=>array(6,'asset4','2013-07-24 12:00:00', '2013-07-24 14:00:00','blue', 3),
6=>array(7,'asset1','2013-07-24 11:45:00', '2013-07-24 13:00:00','red', 1),
7=>array(8,'asset4','2013-07-24 13:00:00', '2013-07-24 15:00:00','yellow', 5)
);
$attrs = array('class' => 'main',
'id' => 'main_id',
'width' => '100%',
'border' => '1',
'cellspacing' => '0',
'cellpadding' => '0');
$table = new HTML_Table($attrs);
$table->setAutoGrow(true);
$table->setAutoFill('n/a');
$heads = array(array('asset1','asset2','asset3','asset4'));
$i = 1;
foreach($heads as $val)
{
$table->setHeaderContents(0, $i++, $val);
unset($val);
}
$now = date('U');
$offset = ($now % 900);
$now = $now-$offset;
for ($i = 0;$i < 33; $i++)
{
$table->setHeaderContents($i,0, date('g:i',$now));
$now += 900;
}
$cellPosition = 1;
$rowCounter = 1;
for ($i=0;$i < count($data);$i++)
{
$table->setCellAttributes ($rowCounter,$cellPosition,' bgcolor = '. $data[$i][4]. ' rowspan=' . $data[$i][5]);
$table->setCellContents($rowCounter,$cellPosition,"Job# ".$data[$i][0] . " belongs to: " . $data[$i][1]);
$cellPosition++;
$rowCounter =1;
}
echo $table->display();
?>
我該如何將信息綁定到它只屬於它的列?
我已經遠遠得到這一點,但我得到奇怪的結果,如果第一列是正確的:
$cellPosition = 0;
$rowCounter = 1;
for ($x=0;$x <= count($heads);$x++)
{
for ($i=0;$i < count($data);$i++)
{
if ($data[$i][1] == $table->getCellContents(0,$x))
{
$table->setCellAttributes ($rowCounter,$cellPosition,' bgcolor = '. $data[$i][4]. ' rowspan=' . $data[$i][5]);
$table->setCellContents($rowCounter,$cellPosition,"Job# ".$data[$i][0] . " belongs to: " . $data[$i][1]);
//$cellPosition++;
//echo ;
echo "<br> The current count of x = : ". $x;
echo "<br>" . $table->getCellContents(0,$x) . " Matches " . $table->getCellContents(0,$x) . " at index " . $i;
$rowCounter += $data[$i][5];
}
else
{
$rowCounter = 1;
}
}
$cellPosition++;
1.瞭解sql注入。 2.沒有必要unset()。 3.這與sql無關。給出一個不需要sql查詢就能運行的最小例子。 4.說出你的期望,以及實際出現的內容。 – cweiske
好吧,表的第一行(來自資產表的資產名稱的標題行)由第一個sql語句'$ sql_assets'填充,然後第一列由for循環填充,以15分鐘爲增量計算時間。然後,通過查詢計劃表創建對象'$ obj',並將該對象(在本例中)傳遞給currentJobsList函數以確定開始時間並將其放入數組中。該數組currentJobs然後用於填充表的內部單元格。然而,它只是把它們放在一起。我需要讓他們在那裏的資產。 – royjm
嘗試將該問題分解爲一些沒有SQL查詢的小代碼示例。 – cweiske