我如何在php中将行数据转换为列,请帮助我

问题描述 投票:0回答:1

我有一个包含数据的学术表。请帮我解决这个问题

例如:

php html pivot fetch
1个回答
0
投票

试试这个:

<table border="1">
    <tr>
        <th>Degree</th>
        <th>Diploma</th>
        <th>Post Diploma</th>
    </tr>

    <?php
    
    $stmt = $conn->prepare("SELECT 
        MAX(CASE WHEN level = 'Degree' THEN percentage END) AS Degree,
        MAX(CASE WHEN level = 'Diploma' THEN percentage END) AS Diploma,
        MAX(CASE WHEN level = 'Post Diploma' THEN percentage END) AS Post_Diploma
        FROM tbl_academic_qualification WHERE member_no = :emp_id");

    
    $stmt->execute();
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        echo "<tr>";
        echo "<td>" . $row['Degree'] . "</td>";
        echo "<td>" . $row['Diploma'] . "</td>";
        echo "<td>" . $row['Post_Diploma'] . "</td>";
        echo "</tr>";
    }
    ?>

</table>
© www.soinside.com 2019 - 2024. All rights reserved.