2

マージされた行を含めるようにページ上のテーブルを変更しようとしています。

以下は、mysql db からの出力を処理する php コードです。

######## PRINT OUT TABLE WITH YEARS AND OFFICES PLUS NAMES IN CELLS ########    
for ($y = $year_max; $y >=$year_min; $y--){
    echo '<tr><th>'.$y.'</th>';

    for ($i = 0; $i<count($offices_used); $i++){

        if (isset($data[$y][$offices_used[$i]])){
            echo '<td>'.$data[$y][$offices_used[$i]].'</td>';
        } // END IF

        else {
            echo '<td></td>';
        } // END ELSE

        }   echo '</tr>';
    } // END FOR 

さらに下のテーブルは、すぐ下のような多次元配列から生成されます。

array (  

[2013] => Array
    (
        [President] => John Mills
        [Internal VP] => Virgil Bagdonas
        [External VP] => Reid Gilmore
        [Treasurer] => Todd Heino
        [Secretary] => Eric Holmquist
        [Newsletter] => Art Bodwell
        [Webmaster] => Dave Eaton
        [Photographer] => Rick Angus
        [Video Librarian] => Mike Peters
        [Store Manager] => Kevin Nee
    )

[2012] => Array
    (
        [President] => Dave Eaton
        [Internal VP] => Jim Metcalf
        [External VP] => Reid Gilmore
        [Treasurer] => Mike Peters
        [Secretary] => Eric Holmquist
        [Newsletter] => Art Bodwell
        [Webmaster] => Dave Eaton
        [Photographer] => Peter Wilcox
        [Video Librarian] => Ray Asselin
        [Store Manager] => Joe Giroux
    )

[2011] => Array
    (
        [President] => Charlie Croteau
        [Internal VP] => Reid Gilmore
        [External VP] => Rick Angus
        [Treasurer] => Mike Peters
        [Secretary] => Eric Holmquist
        [Newsletter] => Ron Rocheleau
        [Webmaster] => Dave Eaton
        [Photographer] => Peter Wilcox
        [Video Librarian] => Ray Asselin
        [Book Librarian] => Roger Boisvert
        [Store Manager] => Mike Smith
    )

...等

私のphpコードは、mysql dbからこのテーブルを生成します:

<tr>
    <th>Year</th>
    <th>President</th>
    <th>Internal VP</th>
    <th>External VP</th>
    <th>Treasurer</th>
    <th>Secretary</th>
    <th>Webmaster</th>
    <th>Newsletter</th>
    <th>Photographer</th>
    <th>Video Librarian</th>
    <th>Book Librarian</th>
    <th>Store Manager</th>
</tr>

<tr>
    <th>2013</th>
    <td>John Mills</td>
    <td>Virgil Bagdonas</td>
    <td>Reid Gilmore</td>
    <td>Todd Heino</td>
    <td>Eric Holmquist</td>
    <td>Dave Eaton</td>
    <td>Art Bodwell</td>
    <td>Rick Angus</td>
    <td>Mike Peters</td>
    <td></td>
    <td>Kevin Nee</td>
</tr>
<tr>
    <th>2012</th>
    <td>Dave Eaton</td>
    <td>Jim Metcalf</td>
    <td>Reid Gilmore</td>
    <td>Mike Peters</td>
    <td>Eric Holmquist</td>
    <td>Dave Eaton</td>
    <td>Art Bodwell</td>
    <td>Peter Wilcox</td>
    <td>Ray Asselin</td>
    <td></td>
    <td>Joe Giroux</td>
</tr>
<tr>
    <th>2011</th>
    <td>Charlie Croteau</td>
    <td>Reid Gilmore</td>
    <td>Rick Angus</td>
    <td>Mike Peters</td>
    <td>Eric Holmquist</td>
    <td>Dave Eaton</td>
    <td>Ron Rocheleau</td>
    <td>Peter Wilcox</td>
    <td>Ray Asselin</td>
    <td>Roger Boisvert</td>
    <td>Mike Smith</td>
</tr>

しかし、配列処理の出力を次のように変更したいと思います。

<tr>
    <th>Year</th>
    <th>President</th>
    <th>Internal VP</th>
    <th>External VP</th>
    <th>Treasurer</th>
    <th>Secretary</th>
    <th>Webmaster</th>
    <th>Newsletter</th>
    <th>Photographer</th>
    <th>Video Librarian</th>
    <th>Book Librarian</th>
    <th>Store Manager</th>
</tr>
<tr>
    <th>2013</th>
    <td>John Mills</td>
    <td>Virgil Bagdonas</td>
    <td rowspan= "3">Reid Gilmore</td>
    <td>Todd Heino</td>
    <td rowspan="3">Eric Holmquist</td>
    <td rowspan="9">Dave Eaton</td>
    <td rowspan="2">Art Bodwell</td>
    <td>Rick Angus</td>
    <td>Mike Peters</td>
    <td></td>
    <td>Kevin Nee</td>
</tr>
<tr>
    <th>2012</th>
    <td>Dave Eaton</td>
    <td>Jim Metcalf</td>
    <td rowspan="2">Mike Peters</td>
    <td>Peter Wilcox</td>
    <td rowspan="3">Ray Asselin</td>
    <td></td>
    <td>Joe Giroux</td>
</tr>
<tr>
    <th>2011</th>
    <td>Charlie Croteau</td>
    <td>Rick Angus</td>
    <td>Ron Rocheleau</td>
    <td>Peter Wilcox</td>
    <td>Roger Boisvert</td>
    <td>Mike Smith</td>
</tr>

これを達成するためにフラグまたはカウンターを追加する方法についてのリードは大歓迎です。ありがとう!

4

3 に答える 3

0

以下を使用して解決:

############################################################################
######## PRINT OUT TABLE WITH YEARS AND OFFICES PLUS NAMES IN CELLS ########    
for ($y = $year_max; $y >=$year_min; $y--){ // Loop through years
    echo '<tr><th>'.$y.'</th>';

    for ($i = 0; $i<count($offices_used); $i++){

        if (isset($data[$y][$offices_used[$i]])){

            $rowz =1;


            if(!($data[$y][$offices_used[$i]] == $data[($y+1)][$offices_used[$i]])){

                while ($data[$y][$offices_used[$i]] == $data[($y-$rowz)][$offices_used[$i]]) $rowz ++; 
                echo '<td rowspan = "'.$rowz.'">'.$data[$y][$offices_used[$i]].'</td>';
            }

        } // END IF

        else {
            echo '<td align = "center"> - </td>';
        } // END ELSE

        }   echo '</tr>';  // End row of current year

} // END FOR Loop through years 
echo '</table>';

結果の出力ページについては、 http://jsfiddle.net/eaton9999/8gMVK/を参照してください。

助けてくれたimsisoと他の人に再び感謝します!

于 2013-05-25T23:19:11.883 に答える