如何在Codeigniter视图中使用HTML标记?

时间:2015-12-29 05:07:09

标签: php html codeigniter

我有PHP代码登录,打印一些这样的数据: output

我想以表格格式打印这些数据,但是当我在代码中写入任何内容时,它会显示错误,所以请在这里帮助我。

下面是我打印此::

的代码
            <?php
            $loginarry = $attendances;
            $logoutarry =$attendances_logouts;
            $timeduration=0;
            $login_i=0;
            $logout_i=0;


            //echo ("Array Length = " . count($loginarry)." & ".count($logoutarry)."\n<br/>");
    while(true)
    { 
        if( $login_i >= count($loginarry) && $logout_i >= count($logoutarry))
            break;

        if( $logout_i >= count($logoutarry))
        {
            echo ("Login[".$login_i."] : ".$loginarry[$login_i]->date_data." and Logout : -----------------\n<br/>");
            $login_i++;
            continue;
        }
        if( $login_i >= count($loginarry))
        {
            echo ("Login : ----------------- and Logout[".$logout_i."] : ".$logoutarry[$logout_i]->date_data."\n<br/>");
                        $logout_i++;
            continue;
        }
        //echo( "******* ".(new DateTime($loginarry[$login_i+1]->date_data))->format('U') . " **** ".(new DateTime($logoutarry[$logout_i]->date_data))->format('U'). "\n<br/>");

        //check if next login time is smaller then current logout time - if so skip current login time
        if($login_i < (count($loginarry)-1) && (new DateTime($logoutarry[$logout_i]->date_data))->format('U') > (new DateTime($loginarry[$login_i+1]->date_data))->format('U'))
        //if( date_diff(date_create($logoutarry[$logout_i]->date_data), date_create($loginarry[$login_i+1]->date_data)) > 0 )
        {
            echo ("Login[".$login_i."] : ".$loginarry[$login_i]->date_data." and Logout : -----------------\n<br/>");
            $login_i++;
            $timeduration += 10;
            continue;
        }
        if( (new DateTime($loginarry[$login_i]->date_data))->format('U') > (new DateTime($logoutarry[$logout_i]->date_data))->format('U') )
        //if( date_diff(date_create($loginarry[$login_i]->date_data), date_create($logoutarry[$logout_i]->date_data)) > 0 )
                {
            echo ("Login : ----------------- and Logout[".$logout_i."] : ".$logoutarry[$logout_i]->date_data."\n<br/>");
                        $logout_i++;
                        $timeduration += 10;
                        continue;
                }

        //if more logout entries then skip to last logout entry
        if( $login_i < (count($loginarry)-1) && $logout_i < (count($logoutarry)-1) && (new DateTime($logoutarry[$logout_i+1]->date_data))->format('U') < (new DateTime($loginarry[$login_i+1]->date_data))->format('U'))
        {
            echo ("Login : ----------------- and Logout[".$logout_i."] : ".$logoutarry[$logout_i]->date_data."\n<br/>");
                        $logout_i++;
                        $timeduration += 10;
                        continue;
        }

        echo ("Login[".$login_i."] : ".$loginarry[$login_i]->date_data." and Logout[".$logout_i."] : ".$logoutarry[$logout_i]->date_data);
        echo (" and Duration = ".((new DateTime($logoutarry[$logout_i]->date_data))->format('U') - (new DateTime($loginarry[$login_i]->date_data))->format('U')) ."\n<br/>");

        $timeduration += ((new DateTime($logoutarry[$logout_i]->date_data))->format('U') - (new DateTime($loginarry[$login_i]->date_data))->format('U'));
        $login_i++;
        $logout_i++;

    }
        echo ("Total Duration = ".$timeduration. " second(s) " );
        echo"<br>";
        echo("Total Duration = ".$timeduration/'3600'."Hours ");


            ?>  

我只想要将这些数据打印在表格中。现在每天的数据都不同了。方案是我有一个数据选择器和下拉列表。现在,当我从列表中选择日期和人物时。它返回有关此人登录和注销信息的登录和注销信息。还有他上任的工作时间。和他离开的时间。

所以请帮我告诉我如何以表格形式打印

newoutput

expected output

1 个答案:

答案 0 :(得分:2)

尝试此代码..可能会解决您的问题。

<?php
        $loginarry = $attendances;
        $logoutarry =$attendances_logouts;
        $timeduration=0;
        $login_i=0;
        $logout_i=0;

        echo '<table>';
        //echo ("Array Length = " . count($loginarry)." & ".count($logoutarry)."\n<br/>");
while(true)
{ 
    if( $login_i >= count($loginarry) && $logout_i >= count($logoutarry))
        break;

    if( $logout_i >= count($logoutarry))
    {
        echo ("<tr><td>Login[".$login_i."] : ".$loginarry[$login_i]->date_data." and Logout : -----------------\n</td></tr>");
        $login_i++;
        continue;
    }
    if( $login_i >= count($loginarry))
    {
        echo ("<tr><td>Login : ----------------- and Logout[".$logout_i."] : ".$logoutarry[$logout_i]->date_data."\n</td></tr>");
                    $logout_i++;
        continue;
    }
    //echo( "******* ".(new DateTime($loginarry[$login_i+1]->date_data))->format('U') . " **** ".(new DateTime($logoutarry[$logout_i]->date_data))->format('U'). "\n<br/>");

    //check if next login time is smaller then current logout time - if so skip current login time
    if($login_i < (count($loginarry)-1) && (new DateTime($logoutarry[$logout_i]->date_data))->format('U') > (new DateTime($loginarry[$login_i+1]->date_data))->format('U'))
    //if( date_diff(date_create($logoutarry[$logout_i]->date_data), date_create($loginarry[$login_i+1]->date_data)) > 0 )
    {
        echo ("<tr><td>Login[".$login_i."] : ".$loginarry[$login_i]->date_data." and Logout : -----------------\n</td></tr>");
        $login_i++;
        $timeduration += 10;
        continue;
    }
    if( (new DateTime($loginarry[$login_i]->date_data))->format('U') > (new DateTime($logoutarry[$logout_i]->date_data))->format('U') )
    //if( date_diff(date_create($loginarry[$login_i]->date_data), date_create($logoutarry[$logout_i]->date_data)) > 0 )
            {
        echo ("<tr><td>Login : ----------------- and Logout[".$logout_i."] : ".$logoutarry[$logout_i]->date_data."\n</td></tr>");
                    $logout_i++;
                    $timeduration += 10;
                    continue;
            }

    //if more logout entries then skip to last logout entry
    if( $login_i < (count($loginarry)-1) && $logout_i < (count($logoutarry)-1) && (new DateTime($logoutarry[$logout_i+1]->date_data))->format('U') < (new DateTime($loginarry[$login_i+1]->date_data))->format('U'))
    {
        echo ("<tr><td>Login : ----------------- and Logout[".$logout_i."] : ".$logoutarry[$logout_i]->date_data."\n</td></tr>");
                    $logout_i++;
                    $timeduration += 10;
                    continue;
    }

    echo ("<tr><td>Login[".$login_i."] : ".$loginarry[$login_i]->date_data." and Logout[".$logout_i."] : ".$logoutarry[$logout_i]->date_data);
    echo (" and Duration = ".((new DateTime($logoutarry[$logout_i]->date_data))->format('U') - (new DateTime($loginarry[$login_i]->date_data))->format('U')) ."\n</td></tr>");

    $timeduration += ((new DateTime($logoutarry[$logout_i]->date_data))->format('U') - (new DateTime($loginarry[$login_i]->date_data))->format('U'));
    $login_i++;
    $logout_i++;

}
    echo ("<tr><td>Total Duration = ".$timeduration. " second(s) </td></tr>" );
    echo"<br>";
    echo("<tr><td>Total Duration = ".$timeduration/'3600'."Hours </td></tr>");


        ?>