如何在PHP中基于年份在表中显示数据
我想根据年份显示重复的首个ID和实际ID。但实际id是唯一的如何在PHP中基于年份在表中显示数据,php,html-table,Php,Html Table,我想根据年份显示重复的首个ID和实际ID。但实际id是唯一的 <?php while($Row=oci_fetch_assoc($Result)){ $ResultArray[$j]['First_ID']=$Row['First_ID']; $ResultArray[$j]['Actual_ID']=$Row['Actual_ID']; $ResultArray[$j]['Title']=$Row['Title']; $Resu
<?php while($Row=oci_fetch_assoc($Result)){
$ResultArray[$j]['First_ID']=$Row['First_ID'];
$ResultArray[$j]['Actual_ID']=$Row['Actual_ID'];
$ResultArray[$j]['Title']=$Row['Title'];
$ResultArray[$j]['START_DATE']=$Row['START_DATE'];
$startDate=explode(' ',$Row['START_DATE']);
$ResultArray[$j]['YEAR']=$startDate[0];
if(($startDate[0])==($startyear)){
$ResultArray[$j][$startyear]['Actual_ID']=$Row['Actual_ID'];
$ResultArray[$j][$startyear]['Other_ID']=$Row['Other_ID'];
$ResultArray[$j][$startyear]['Content']=$Row['Content'];
}
if(($startDate[0])==($startyear+1)){
$ResultArray[$j][$startyear+$i]['Actual_ID']=$Row['Actual_ID'];
$ResultArray[$j][$startyear+$i]['Other_ID']=$Row['Other_ID'];
$ResultArray[$j][$startyear+$i]['Content']=$Row['Content'];
}
if(($startDate[0])==($startyear+1)){
$ResultArray[$j][$startyear+$i]['Actual_ID']=$Row['Actual_ID'];
$ResultArray[$j][$startyear+$i]['Other_ID']=$Row['Other_ID'];
$ResultArray[$j][$startyear+$i]['Content']=$Row['Content'];
}
$j++;
}?>
//在表格中显示
它首先显示asc订单的年份,然后显示下一年等
<table class="tab">
<tr><th>S.No</th>
<th>first_ id</th><th>Title</th>
<?phpfor($i=0;$i<4;$i++){?><th colspan="3"><?php echo $startyear+$i; ?> </th>
<?php }?>
<tr><th></th><th></th><th></th>
<th>Actual_ID</th><th>Other_ID</th><th>Content</th>
<th>Actual_ID</th><th>Other_ID</th> <th>Content</th>
<th>Actual_ID</th><th>Other_ID</th><th>Content</th>
<th>Actual_ID</th><th>Other_ID</th><th>Content</th></tr>
<?php
foreach($ResultArray as $ResultArray1){
//print_r($abstarctResultArray1);
?><tr><td><?php echo $count; $count++;?></td>
<td><?php echo $ResultArray1['First_ID'];?></td>
<td><?php echo $ResultArray1['Title'];?></td>
<?php for($i=0;$i<4;$i++){
$startDate=explode(' ',$ResultArray1['START_DATE']);
if(($startDate[0]==$startyear)){?>
<td><?php echo $ResultArray1[$startDate[0]['Actual_ID'];?></td>
<td><?php echo $ResultArray1[$startDate[0]['Other_ID'];?></td>
<td><?php echo $ResultArray1[$startDate[0]['Content'];?></td>
<?php }
else if(($startDate[0]==$startyear+1)){?>
<td><?php echo $ResultArray1[$startDate[0]['Actual_ID'];?></td>
<td><?php echo $ResultArray1[$startDate[0]['Other_ID'];?></td>
<td><?php echo $ResultArray1[$startDate[0]['Content'];?></td>
</tr>
<?php
}
else if(($startDate[0]==$startyear+2)){?>
<td><?php echo $ResultArray1[$startDate[0]['Actual_ID'];?></td>
<td><?php echo $ResultArray1[$startDate[0]['Other_ID'];?></td>
<td><?php echo $ResultArray1[$startDate[0]['Content'];?></td>
</tr>
<?php
}
}
}
?>
美国号
第一个标题
实际\u i其他\u i内容
实际\u i其他\u ID内容
实际\u i其他\u i内容
实际\u i其他\u i内容
我尝试过不同的想法,但我做不到。请帮忙
我的建议是:如果你把代码精简到你的问题上,那会很有帮助。我知道当我抱怨的时候,我代表了很多人。如果90%的代码与问题无关,那么研究一个问题就不太有吸引力了。我对您所寻找的输出感到非常困惑。。即使添加一个期望的输出图像也有助于更好地理解这个问题。我不完全确定你要的是什么,你能澄清一下你想要实现什么,以及现有代码有什么问题吗?我已经编辑过了。请现在检查。在表中连接数据并显示它可能更容易。您的表和查询如何?我的建议是:如果您将代码精简到您的问题,这将非常有帮助。我知道当我抱怨的时候,我代表了很多人。如果90%的代码与问题无关,那么研究一个问题就不太有吸引力了。我对您所寻找的输出感到非常困惑。。即使添加一个期望的输出图像也有助于更好地理解这个问题。我不完全确定你要的是什么,你能澄清一下你想要实现什么,以及现有代码有什么问题吗?我已经编辑过了。请现在检查。在表中连接数据并显示它可能更容易。您的表和查询如何?