如何根据PHP中的年份在表格中显示数据

时间:2015-10-12 08:44:29

标签: php html-table

我希望根据年份重复显示first_id和实际ID来显示。但是actual_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'];
        $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
    }
    }
    }
?>

我尝试过不同的想法,但我做不到。请帮忙。

i want the below output

0 个答案:

没有答案