0

PHP 内に単純な html テーブルを作成しました。これが私のコードです:

<div id="wrapper">
    <div class="chart">
        <h2>Files Uploaded to Knowledge Base</h2>
        <table id="data-table" border="1" cellpadding="10" cellspacing="0">


        <tr id=header>
                <td>Users</td>
                <td id=center>Project Files</td>
                <td id=center>Process Files</td>
                <td id=center>System Files</td>
                <td id=center>Total Files</td>
        </tr>   

                    <?php

                    $di = new RecursiveDirectoryIterator('upload/project/');
                    foreach (new RecursiveIteratorIterator($di) as $filename => $file) {

                    $pos = 15;
                    $file = substr("$filename", +$pos); 

                    $lenght = strlen($file);
                    $pos = strpos($file, "/");
                    $file = substr("$file",0,$pos);
                    if($file1 != '.DS_Store'){

                        $serverfiles = mysql_query("SELECT uploader FROM Project WHERE location = '$file'");

                        while($row = mysql_fetch_array($serverfiles)) {
                            $occurance1 = $row['uploader'];
                            $array1[] = $occurance1; 
                            }
                        }                           
                    }




                    $di = new RecursiveDirectoryIterator('upload/process/');
                    foreach (new RecursiveIteratorIterator($di) as $filename => $file) {

                    $pos = 15;
                    $file = substr("$filename", +$pos);                         
                    $lenght = strlen($file);
                    $pos = strpos($file, "/");
                    $file = substr("$file",0,$pos);

                    if($file != '.DS_Store'){

                        $serverfiles = mysql_query("SELECT uploader FROM Process WHERE processlocation = '$file'");

                        while($row = mysql_fetch_array($serverfiles)) {
                            $occurance2 = $row['uploader'];
                            $array2[] = $occurance2; 
                            }
                        }                           
                    }

                    $di = new RecursiveDirectoryIterator('upload/system/');
                    foreach (new RecursiveIteratorIterator($di) as $filename => $file) {

                    $pos = 14;
                    $file = substr("$filename", +$pos);                         
                    $lenght = strlen($file);
                    $pos = strpos($file, "/");
                    $file = substr("$file",0,$pos);
                    if($file != '.DS_Store'){

                        $serverfiles = mysql_query("SELECT uploader FROM System WHERE location = '$file'");

                        while($row = mysql_fetch_array($serverfiles)) {
                            $occurance3 = $row['uploader'];
                            $array3[] = $occurance3; 
                            }
                        }                           
                    }

                    $table_rows = array();
                    $counter = 0;
                    $uploader = mysql_query("Select username from members");
                    while($Load = mysql_fetch_array($uploader)){
                    $value = $Load['username'];

                    $tmp = array_count_values($array1);
                    $cnt = $tmp[$value];

                    $tmp2 = array_count_values($array2);
                    $cnt2 = $tmp2[$value];

                    $tmp3 = array_count_values($array3);
                    $cnt3 = $tmp3[$value];

                    $total = $cnt + $cnt2 + $cnt3;

                    //putting the values into array
                    $counter++;
                    $table_rows[$counter] = array();
                    $table_rows[$counter]['username'] = $value;
                    $table_rows[$counter]['project'] = $cnt;
                    $table_rows[$counter]['process'] = $cnt2;
                    $table_rows[$counter]['system'] = $cnt3;
                    $table_rows[$counter]['total'] = $total;
                    }

                    //function to sort the highest total value
                    function cmp_rows($a,$b) {
                    if ($a['total'] == $b['total']) {
                    return 0;
                    }
                    return ($a['total'] > $b['total']) ? -1 : 1;
                    }

                    usort($table_rows, 'cmp_rows');

                    //loop that prints values
                    foreach($table_rows as $row) {
                    echo "<tr>";
                    echo "<td>{$row['username']}</td>";
                    echo"<td id=center>{$row['project']}</td>";
                    echo"<td id=center>{$row['process']}</td>";
                    echo "<td id=center>{$row['system']}</td>";
                    echo "<td id=center>{$row['total']}</td>";
                    }


                    ?>

        </table>

   </div>

    </body></html>

ユーザーは、データベース テーブルから入力されます。ファイルの数字は、ディレクトリ内のファイルの量を読み取ってカウントすることによって生成されます。テーブルは最高のものから順にソートされます。各メンバーのメンバー テーブルの「accessDate」列の値も表示したいのですが、これを行う方法がわかりません。上記の他の値のようには機能しません..

これを行う方法がわかりません。誰かが私を正しい方向に導いてくれますか?

ありがとう!

4

1 に答える 1

0

テーブルに書式設定された日付を取得しようとしているだけの場合は、次のような方法で実行できます (- http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.htmlを参照) #function_date-format (MySQL の日付フォーマット用)

...
//MySQL can format the date for you
$uploader = mysql_query(
    "Select username, DATE_FORMAT(accessDate,'%m %d, %Y') formatted_date from members");
while($Load = mysql_fetch_array($uploader))
{
...
    //putting the values into array
    $counter++;
    $table_rows[$counter] = array();
    $table_rows[$counter]['date'] = $Load['formatted_date'];
    $table_rows[$counter]['username'] = $value;
...
}
...
foreach($table_rows as $row)
{
                echo "<tr>";
                echo "<td>{$row['username']}</td>";
                echo "<td>{$row['date']}</td>";
...
}
...
于 2013-01-28T12:17:53.763 に答える