![](/img/trans.png)
[英]Reading and inserting part of a csv file using php - not wanting repeating data
[英]How to hide repeating part of the retrieved data values using php and codeigniter
由於這個MySQL語句,我已經獲得了下表
SELECT * FROM expenses, income
WHERE expenses.projectname=income.projectname
AND expenses.task=income.task
在此表中,一個項目有許多任務。 因此項目,客戶,項目開始和結束日期列無意義地重復。 如何才能為所有任務顯示一次? 如何在這里應用PHP隱藏邏輯? 下圖顯示了我需要實現的目標。 通過MySQL查詢檢索數據。 但是我怎樣才能隱藏重復的不必要的值 這是CodeIgniter視圖頁面
<table class="table table-lg">
<thead >
<tr class="filters">
<th><input type="text" class="form-control" placeholder="Project" disabled></th>
<th><input type="text" class="form-control" placeholder="Employee" disabled></th>
<th><input type="text" class="form-control" placeholder="Task" disabled></th>
<th><input type="text" class="form-control" placeholder="Expense" disabled></th>
<th><input type="text" class="form-control" placeholder="Amount" disabled></th>
<th><input type="text" class="form-control" placeholder="Paid/Not" disabled></th>
<th><input type="text" class="form-control" placeholder="Client" disabled></th>
<th><input type="text" class="form-control" placeholder="Cost" disabled></th>
<th><input type="text" class="form-control" placeholder="Income " disabled></th>
<th><input type="text" class="form-control" placeholder="Date" disabled></th>
</tr>
</thead>
<tbody>
<?php
if(isset($view_data1) && is_array($view_data1) && count($view_data1)): $i=1;
foreach ($view_data1 as $key => $data) {
?>
<tr <?php if($i%2==0){echo 'class="even"';}else{echo'class="odd"';}?>>
<td><?php echo $data['projectname']; ?></td>
<td><?php echo $data['employee']; ?></td>
<td><?php echo $data['task']; ?></td>
<td><?php echo $data['ExpenseName']; ?></td>
<td><?php echo $data['ExpenseAmount']; ?></td>
<td><?php echo $data['pn']; ?></td>
<td><?php echo $data['cname']; ?></td>
<td><?php echo $data['taskcost']; ?></td>
<td><?php echo $data['amount']; ?></td>
<td><?php echo $data['datetimepicker_mask']; ?></td>
</tr>
<?php
$i++;
}
else:
?>
<tr>
<td colspan="7" align="center" >No Records Found..</td>
</tr>
<?php
endif;
?>
</tbody>
</table>
我沒有測試這段代碼,但想法是記住最后一個密鑰(在這種情況下為projectname和employee),然后將它與當前密鑰進行比較。
示例代碼中的字段與您的Word文檔示例表不匹配,因此我只使用了您的代碼示例。
<tbody>
<?php
if (isset($view_data1) && is_array($view_data1) && count($view_data1)) {
$i = 1;
$last_key = '';
foreach ($view_data1 as $key => $data) {
$stripe = 'odd';
if ($i % 2 == 0) {
$stripe = 'even';
}
echo "<tr class='$stripe'>";
$i++;
$current_key = $data['projectname'] . $data['employee'];
if ($current_key !== $last_key) {
echo "<td>" . $data['projectname'] . "</td>";
echo "<td>" . $data['employee'] . "</td>";
} else {
echo "<td colspan='2'></td>";
}
$last_key = $current_key;
?>
<td><?php echo $data['task']; ?></td>
<td><?php echo $data['ExpenseName']; ?></td>
<td><?php echo $data['ExpenseAmount']; ?></td>
<td><?php echo $data['pn']; ?></td>
<td><?php echo $data['cname']; ?></td>
<td><?php echo $data['taskcost']; ?></td>
<td><?php echo $data['amount']; ?></td>
<td><?php echo $data['datetimepicker_mask']; ?></td>
</tr>
<?php
}
} else {
?>
<tr><td colspan="10" align="center" >No Records Found..</td></tr>
<?php
}
?>
</tbody>
</table>
當時不要選擇兩張桌子。 加入條件。
SELECT expenses.*,income.*,expenses.id as p_id FROM expenses
join income ON expenses.task=income.task AND expenses.projectname=income.projectname
改變你對foreach部分的看法
<table class="table table-lg">
<thead >
<tr class="filters">
<th ><input type="text" class="form-control" placeholder="Project" disabled></th>
<th ><input type="text" class="form-control" placeholder="Employee" disabled></th>
<th ><input type="text" class="form-control" placeholder="Task" disabled></th>
<th ><input type="text" class="form-control" placeholder="Expense" disabled></th>
<th ><input type="text" class="form-control" placeholder="Amount" disabled></th>
<th ><input type="text" class="form-control" placeholder="Paid/Not" disabled></th>
<th ><input type="text" class="form-control" placeholder="Client" disabled></th>
<th ><input type="text" class="form-control" placeholder="Cost" disabled></th>
<th ><input type="text" class="form-control" placeholder="Income " disabled></th>
<th ><input type="text" class="form-control" placeholder="Date" disabled></th>
</tr>
</thead>
<tbody>
<?php
if(isset($view_data1) && is_array($view_data1) && count($view_data1)): $i=1;
$is_exists=array();
foreach ($view_data1 as $key => $data) {
?>
<tr <?php if($i%2==0){echo 'class="even"';}else{echo'class="odd"';}?>>
<?php
if(!in_array($data['p_id'], $is_exists)){
$is_exists[]=$data['p_id'];
?>
<td><?php echo $data['projectname']; ?></td>
<td><?php echo $data['employee']; ?></td>
<td><?php echo $data['task']; ?></td>
<td><?php echo $data['ExpenseName']; ?></td>
<?php
}else{
echo "<td rowspan='4'></td>";
}
?>
<td><?php echo $data['ExpenseAmount']; ?></td>
<td><?php echo $data['pn']; ?></td>
<td><?php echo $data['cname']; ?></td>
<td><?php echo $data['taskcost']; ?></td>
<td><?php echo $data['amount']; ?></td>
<td><?php echo $data['datetimepicker_mask']; ?></td>
</tr>
<?php
$i++;
}
else:
?>
<tr>
<td colspan="7" align="center" >No Records Found..</td>
</tr>
<?php
endif;
?>
</tbody>
</table>
不要合並這樣的表。 在模型中使用連接查詢,並通過控制器在視圖中調用它
public function getExpenses(){
$this->db->select("addexpense.exp_date, addexpense.exp_amount, addexpense.exp_note, addexpense.exp_created, addcategory.category_name");
$this->db->from('addexpense');
$this->db->join('addcategory', 'addcategory.category_id = addexpense.category_id');
$query = $this->db->get();
return $query->result();
}
如果我理解你,你可以試試以下。
<?php
$arrData = [
[
"projectname" => "First Project",
"employee" => "First Client",
"projectstart" => "12-12-2017",
"projectend" => "12-12-2019",
"task" => "Task 1",
"description" => "Description 1",
"commission" => "1000",
"taststart" => "01-01-2018",
"taskend" => "10-01-2018"
],
[
"projectname" => "First Project",
"employee" => "First Client",
"projectstart" => "12-12-2017",
"projectend" => "12-12-2019",
"task" => "Task 2",
"description" => "Description 2",
"commission" => "1000",
"taststart" => "01-01-2018",
"taskend" => "10-01-2018"
],
[
"projectname" => "First Project",
"employee" => "First Client",
"projectstart" => "12-12-2017",
"projectend" => "12-12-2019",
"task" => "Task 3",
"description" => "Description 3",
"commission" => "1000",
"taststart" => "01-01-2018",
"taskend" => "10-01-2018"
],
[
"projectname" => "Second Project",
"employee" => "Second Client",
"projectstart" => "12-12-2017",
"projectend" => "12-12-2019",
"task" => "Task 4",
"description" => "Description 4",
"commission" => "1000",
"taststart" => "01-01-2018",
"taskend" => "10-01-2018"
],
[
"projectname" => "Second Project",
"employee" => "Second Client",
"projectstart" => "12-12-2017",
"projectend" => "12-12-2019",
"task" => "Task 5",
"description" => "Description 5",
"commission" => "1000",
"taststart" => "01-01-2018",
"taskend" => "10-01-2018"
],
[
"projectname" => "Second Project",
"employee" => "Second Client",
"projectstart" => "12-12-2017",
"projectend" => "12-12-2019",
"task" => "Task 6",
"description" => "Description 6",
"commission" => "1000",
"taststart" => "01-01-2018",
"taskend" => "10-01-2018"
],
];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Project</th>
<th>Client</th>
<th>Project start on</th>
<th>Project end on</th>
<th>task</th>
<th>description</th>
<th>commission</th>
<th>task start on</th>
<th>task end on</th>
</tr>
</thead>
<tbody>
<?php
$strSavedProjectName = false;
foreach($arrData AS $arrItem)
{
?>
<tr>
<?php
if (!$strSavedProjectName || $strSavedProjectName!= $arrItem['projectname']) :
?>
<td><?=$arrItem['projectname']; ?>
<td><?=$arrItem['employee']; ?>
<td><?=$arrItem['projectstart']; ?>
<td><?=$arrItem['projectend']; ?>
<?php
else :
?>
<td colspan="4"></td>
<?php
endif;
?>
<td><?=$arrItem['task']; ?>
<td><?=$arrItem['description']; ?>
<td><?=$arrItem['commission']; ?>
<td><?=$arrItem['taststart']; ?>
<td><?=$arrItem['taskend']; ?>
</tr>
<?php
$strSavedProjectName = $arrItem['projectname'];
}
?>
</tbody>
</table>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</body>
</html>
這是一個完整的示例,基於您的數據 - 因此您應該能夠輕松地將其轉換為您的視圖。
邏輯
我實現的隱藏邏輯按以下順序工作:
HTML表和PHP如下所示:
<table border="1">
<thead>
<tr>
<th>Project</th>
<th>Client</th>
<th>Project Start</th>
<th>Project End</th>
<th>Task</th>
<th>Description</th>
<th>Commission</th>
<th>Task Start</th>
<th>Task End</th>
</tr>
</thead>
<tbody>
<!-- Initial Condition -->
<?php $the_project = "";?>
<!-- Main Loop -->
<?php foreach ($data as $x => $datum) { ?>
<tr>
<!-- Condition Check -->
<!-- If not the same with the last project, it will show the columns. -->
<!-- That's why the Initial Condition is empty so that the 1st time this Condition Check run will always result true. -->
<?php if($datum['project'] != $the_project) { ?>
<td><?php echo $datum['project'];?></td>
<td><?php echo $datum['client'];?></td>
<td><?php echo $datum['proj_start'];?></td>
<td><?php echo $datum['proj_end'];?></td>
<?php } else { ?>
<td colspan="4"> </td>
<?php } ?>
<!-- /Condition Check -->
<td><?php echo $datum['task'];?></td>
<td><?php echo $datum['desc'];?></td>
<td><?php echo $datum['commission'];?></td>
<td><?php echo $datum['task_start'];?></td>
<td><?php echo $datum['task_end'];?></td>
</tr>
<!-- Remember Last Condition -->
<?php $the_project = $datum['project'];?>
<?php }?>
<!-- /Main Loop -->
</tbody>
</table>
您不必比較所有Project
, Client
, Start Date
和End Date
,假設同一項目將具有相同的Client
, Start Date
和End Date
。 這就是為什么它只比較項目( $the_project
)。
數據
您可以將此作為樣本數據使用,就像查詢中的數據一樣。
<?php
$data = array(
array(
"project" => "Mobile App",
"client" => "Client One",
"proj_start"=> "12-12-2017",
"proj_end" => "12-12-2019",
"task" => "task 1",
"desc" => "desc 1",
"commission"=> "1000",
"task_start"=> "01-01-2018",
"task_end" => "10-01-2018"
),
array(
"project" => "Mobile App",
"client" => "Client One",
"proj_start"=> "12-12-2017",
"proj_end" => "12-12-2019",
"task" => "task 2",
"desc" => "desc 2",
"commission"=> "1000",
"task_start"=> "01-02-2018",
"task_end" => "10-02-2018"
),
array(
"project" => "Mobile App",
"client" => "Client One",
"proj_start"=> "12-12-2017",
"proj_end" => "12-12-2019",
"task" => "task 3",
"desc" => "desc 3",
"commission"=> "1000",
"task_start"=> "01-04-2018",
"task_end" => "10-05-2018"
),
array(
"project" => "Web App",
"client" => "Client Two",
"proj_start"=> "12-12-2017",
"proj_end" => "12-12-2019",
"task" => "task 1",
"desc" => "desc 1",
"commission"=> "1000",
"task_start"=> "01-01-2018",
"task_end" => "10-01-2018"
),
array(
"project" => "Web App",
"client" => "Client Two",
"proj_start"=> "12-12-2017",
"proj_end" => "12-12-2019",
"task" => "task 2",
"desc" => "desc 2",
"commission"=> "1000",
"task_start"=> "01-02-2018",
"task_end" => "10-02-2018"
)
);
?>
提示1
我認為不再需要$i
,因為您可以從代碼示例中的$key
獲得相同的結果。 唯一的區別是$key
從0開始。
提示2
如果您仍然需要$i
,則可以簡化此代碼
<tr <?php if($i%2==0){echo 'class="even"';}else{echo'class="odd"';}?>>
成
<tr class="<?php echo ($i%2==0) ? "even":"odd" ?>">
提示3
我不知道你的<tr>
偶數或奇數類的目的,但如果你想為每個類設計不同的顏色,你可能想檢查Bootstrap並將其設置為<table class="table table-striped">
編輯查詢為SELECT * FROM expenses, income WHERE expenses.projectname=income.projectname AND expenses.task=income.task Blockquote GROUP BY PROJECTID
首先,您應該重新安排$ viewdata1數據結構。 基本上,在主項目數據字段和任務數據字段之間分開,然后以更好的方式組合它們。
我的假設是:
1. [task,ExpenseName,ExpenseAmount,pn,cname,taskcost,amount,datetimepicker_mask] =>都是任務數據字段
2. [projectname,employee] =>是所有項目數據字段
在你的模型中 (讓我們將它命名為project_model ),
1.具有僅查詢[projectname或employee或projectID或所有其他項目數據字段]的函數 ,讓我們將其命名為allProject() 。 確保它返回類似的東西
[
0 => [
'id' => 101,
'projectName' => 'Desktop App' ,
other project data fields
] ,
1 => [
'id' => 102,
'projectName' => 'Mobile App' ,
other project data fields
] ,
2 => [
'id' => 103,
'projectName' => 'Andriod App' ,
other project data fields
] ,
etc...
]
2.具有基於[projectname或projectID]搜索/查詢[task,ExpenseName,ExpenseAmount,pn,cname,taskcost,amount,datetimepicker_mask]的函數...讓我們將其命名為task_query(projectID) ...確保它返回類似的東西
[
0 => [
'id' => 222,
'projectID' => 101
'task' => 'task 1',
'description' => 'description 1',
other task data fields
] ,
1 => [
'id' => 236,
'projectID' => 101
'task' => 'task 2',
'description' => 'description 2',
other task data fields
] ,
2 => [
'id' => 245,
'projectID' => 101
'task' => 'task 3',
'description' => 'description 3',
other task data fields
] ,
etc.
]
在控制器中 ,
$data['viewdata1'] = $this->project_model->allProject();
foreach($data['viewdata1'] as $key => $value)
{
$value['taskData'] = $this->project_model->task_query($value['id']);
}
$ data ['viewdata1']應該看起來像......
[
0 => [
'id' => 101,
'projectName' => 'Desktop App' ,
other project data fields,
'taskData' => [
0 => [
'id' => 222,
'projectID' => 101,
'task' => 'task 1',
'description' => 'description 1',
other task data fields
] ,
1 => [
'id' => 236,
'projectID' => 101,
'task' => 'task 2',
'description' => 'description 2',
other task data fields
] ,
2 => [
'id' => 245,
'projectID' => 101,
'task' => 'task 3',
'description' => 'description 3',
other task data fields
] ,
etc.
]
] ,
1 => [
'id' => 102,
'projectName' => 'Mobile App' ,
other project data fields,
'taskData' => [
0 => [
'id' => 123,
'projectID' => 102,
'task' => 'task 1b',
'description' => 'description 1b',
other task data fields
] ,
1 => [
'id' => 124,
'projectID' => 102,
'task' => 'task 2b',
'description' => 'description 2b',
other task data fields
] ,
2 => [
'id' => 125,
'projectID' => 102,
'task' => 'task 3b',
'description' => 'description 3b',
other task data fields
] ,
etc.
]
] ,
2 => [
'id' => 103,
'projectName' => 'Andriod App' ,
other project data fields,
'taskData' => [
0 => [
'id' => 567,
'projectID' => 103,
'task' => 'task 1c',
'description' => 'description 1c',
other task data fields
] ,
1 => [
'id' => 568,
'projectID' => 103,
'task' => 'task 2c',
'description' => 'description 2c',
other task data fields
] ,
2 => [
'id' => 569,
'projectID' => 103,
'task' => 'task 3c',
'description' => 'description 3c',
other task data fields
] ,
etc.
]
] ,
etc...
]
你們都為觀點做好了准備
<table class="table table-lg">
<thead >
<tr class="filters">
<th><input type="text" class="form-control" placeholder="Project" disabled></th>
<th><input type="text" class="form-control" placeholder="Employee" disabled></th>
<th><input type="text" class="form-control" placeholder="Task" disabled></th>
<th><input type="text" class="form-control" placeholder="Expense" disabled></th>
<th><input type="text" class="form-control" placeholder="Amount" disabled></th>
<th><input type="text" class="form-control" placeholder="Paid/Not" disabled></th>
<th><input type="text" class="form-control" placeholder="Client" disabled></th>
<th><input type="text" class="form-control" placeholder="Cost" disabled></th>
<th><input type="text" class="form-control" placeholder="Income " disabled></th>
<th><input type="text" class="form-control" placeholder="Date" disabled></th>
</tr>
</thead>
<tbody>
<?php
if(isset($view_data1) && is_array($view_data1) && count($view_data1)): $i=1;
foreach ($view_data1 as $key1 => $data1) {
$howManyTasks = count($data1['taskData']);
?>
<tr <?php if($i%2==0){echo 'class="even"';}else{echo'class="odd"';}?>>
<td rowspan="<?= $howManyTasks ?>"><?php echo $data1['projectname']; ?></td>
<td rowspan="<?= $howManyTasks ?>"><?php echo $data1['employee']; ?></td>
<?php foreach($data1['taskData'] as $key2 => $data2) {?>
<td><?php echo $data2['task']; ?></td>
<td><?php echo $data2['ExpenseName']; ?></td>
<td><?php echo $data2['ExpenseAmount']; ?></td>
<td><?php echo $data2['pn']; ?></td>
<td><?php echo $data2['cname']; ?></td>
<td><?php echo $data2['taskcost']; ?></td>
<td><?php echo $data2['amount']; ?></td>
<td><?php echo $data2['datetimepicker_mask']; ?></td>
</tr>
<?php if($key2 != ($howManyTasks-1) ){ ?> <tr> <?php } ?>
<?php } ?>
<?php
$i++;
}
else:
?>
<tr>
<td colspan="7" align="center" >No Records Found..</td>
</tr>
<?php
endif;
?>
</tbody>
</table>
if($key == 0){
$project_name = $data['projectname'];
$first = true;
}else{
$first = false;
if($project_name != $data['projectname']){
$project_name = $data['projectname'];
$first = true;
}
}
<td><?php
if($first == true){
ehco $data['projectname'];
}else{
echo "";
}
</td>
在你的foreach中嘗試這樣的我沒有厭倦但它可能有用,你可能會得到一些想法。 在第一個循環中,它將檢查$ key,首先它將為0,如果$ key不為0,則$ first變量將為true然后它將檢查$ project name到循環項目名稱,如果它不匹配則將替換它。 對要刪除或清空的客戶端和其他列使用相同的列表。 我希望這可行或者它會給你一些想法。
使用in_array()
函數並為你的td
設置你的colspan
和rowspan
在您的視圖頁面中使用以下代碼,
<table class="table table-lg">
<thead >
<tr class="filters">
<th><input type="text" class="form-control" placeholder="Project" disabled></th>
<th><input type="text" class="form-control" placeholder="Employee" disabled></th>
<th><input type="text" class="form-control" placeholder="Task" disabled></th>
<th><input type="text" class="form-control" placeholder="Expense" disabled></th>
<th><input type="text" class="form-control" placeholder="Amount" disabled></th>
<th><input type="text" class="form-control" placeholder="Paid/Not" disabled></th>
<th><input type="text" class="form-control" placeholder="Client" disabled></th>
<th><input type="text" class="form-control" placeholder="Cost" disabled></th>
<th><input type="text" class="form-control" placeholder="Income " disabled></th>
<th><input type="text" class="form-control" placeholder="Date" disabled></th>
</tr>
</thead>
<tbody>
<?php
if(isset($view_data1) && is_array($view_data1) && count($view_data1)): $i=1;
foreach ($view_data1 as $key => $data)
{
$number_of_task[$data['projectname']][] = $data['task'];
}
foreach ($view_data1 as $key => $data) {
$array = array();
?>
<tr <?php if($i%2==0){echo 'class="even"';}else{echo'class="odd"';}?>>
<?php if(!in_array($data['projectname'],$array)) {
$array[] = $data['projectname'];
?>
<td><?php echo $data['projectname']; ?></td>
<td><?php echo $data['employee']; ?></td>
<?php } else { ?>
<td colspan="2" rowspan="<?php echo count($number_of_task[$data['projectname']]); ?>"> </td>
<td><?php echo $data['task']; ?></td>
<td><?php echo $data['ExpenseName']; ?></td>
<td><?php echo $data['ExpenseAmount']; ?></td>
<td><?php echo $data['pn']; ?></td>
<td><?php echo $data['cname']; ?></td>
<td><?php echo $data['taskcost']; ?></td>
<td><?php echo $data['amount']; ?></td>
<td><?php echo $data['datetimepicker_mask']; ?></td>
</tr>
<?php
$i++;
}
}
else:
?>
<tr>
<td colspan="7" align="center" >No Records Found..</td>
</tr>
<?php
endif;
?>
</tbody>
</table>
這是我處理它的方式。 我希望這和你遇到的問題一樣:)
*重要的是,變量$ dcost和$ cd是我自己設置的變量,請根據你的需要進行調整
foreach(your sql variable){
echo '<tr><td style="border-right:1px solid #000;text-align:center;vertical-align:middle;">'.$dcost['destination'].'</td>
<td style="border-right:1px solid #000;text-align:center;vertical-align:middle;">'.$dcost['timein'].'</td>
<td style="border-right:1px solid #000;text-align:center;vertical-align:middle;">'.$dcost['timein'].'</td>
<td style="border-right:1px solid #000;text-align:center;vertical-align:middle;">'.$dcost['timein'].'</td>
<td style="border-right:1px solid #000;text-align:center;vertical-align:middle;">'.$dcost['timeout'].'</td>';
<td style="border-right:1px solid #000;text-align:center;vertical-align:middle;" class="mday">'.$cd['mday'].'</td><td style="border-right:1px solid #000;text-align:center;vertical-align:middle;" data-mrate="'.$cd['mrate'].'" class="mrate">'.rupiah($cd['mrate']).'</td><td style="border-right:1px solid #000;text-align:center;vertical-align:middle;" class="tm"></td><td style="border-right:1px solid #000;text-align:center;vertical-align:middle;" class="lday">'.$cd['lday'].'</td><td style="border-right:1px solid #000;text-align:center;vertical-align:middle;" data-lrate="'.$cd['lrate'].'" class="lrate">'.rupiah($cd['lrate']).'</td><td style="border-right:1px solid #000;text-align:center;vertical-align:middle;" class="tl"></td></tr>';}
代碼之后
foreach(your sql variable){
echo '<tr>';
if($i - 1 == 1){
$i = 0;
echo ' <td style="border-right:1px solid #000;text-align:center;vertical-align:middle;">'.$dcost['destination'].'</td>
<td style="border-right:1px solid #000;text-align:center;vertical-align:middle;">'.$dcost['timein'].'</td>
<td style="border-right:1px solid #000;text-align:center;vertical-align:middle;">'.$dcost['timein'].'</td>
<td style="border-right:1px solid #000;text-align:center;vertical-align:middle;">'.$dcost['timein'].'</td>
<td style="border-right:1px solid #000;text-align:center;vertical-align:middle;">'.$dcost['timeout'].'</td>';
}else{
echo ' <td colspan="5" style="border-right:1px solid #000;"> </td>';
}
echo '<td style="border-right:1px solid #000;text-align:center;vertical-align:middle;" class="mday">'.$cd['mday'].'</td><td style="border-right:1px solid #000;text-align:center;vertical-align:middle;" data-mrate="'.$cd['mrate'].'" class="mrate">'.rupiah($cd['mrate']).'</td><td style="border-right:1px solid #000;text-align:center;vertical-align:middle;" class="tm"></td><td style="border-right:1px solid #000;text-align:center;vertical-align:middle;" class="lday">'.$cd['lday'].'</td><td style="border-right:1px solid #000;text-align:center;vertical-align:middle;" data-lrate="'.$cd['lrate'].'" class="lrate">'.rupiah($cd['lrate']).'</td><td style="border-right:1px solid #000;text-align:center;vertical-align:middle;" class="tl"></td></tr>';}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.