-2

我有一张表格,显示 25 个问题的分数。答案范围从 1 到 5。答案是从每个用户的数据库中检索的,如下所示。我尝试了几种方法,但通常需要添加

希望可以有人帮帮我

<table id="stats_table" border="1" width="50px">
    <tr>
        <th>Score</th>
    </tr>
    <?php
        global $wpdb;
        $current_user = wp_get_current_user();
        $result = $wpdb->get_results( "
            SELECT stats.*
            FROM wp_wp_pro_quiz_statistic stats
            JOIN wp_wp_pro_quiz_statistic_ref refs on stats.statistic_ref_id =   refs.statistic_ref_id
            WHERE refs.user_id= $current_user->ID ");
        foreach($result as $row) {
            echo "<tr><td><b>$row->points</b></td></tr>";
        }
    ?>
</table>

/*Final Score Table*/
<table width="960px" border="1">
    <tbody>
        <tr>
            <td width="445px">Total Score (Maximum 125)</td>
            <td width="50px">?</td>
        </tr>
     </tbody>
</table>
4

1 回答 1

1
<table id="stats_table" border="1" width="50px">
        <tr>
            <th>Score</th>
        </tr>
<?php
global $wpdb;
$total_score = 0;
$current_user = wp_get_current_user();
$result = $wpdb->get_results( "
SELECT stats.*
  FROM wp_wp_pro_quiz_statistic stats
       JOIN wp_wp_pro_quiz_statistic_ref refs on stats.statistic_ref_id = refs.statistic_ref_id
WHERE refs.user_id= $current_user->ID ");
foreach($result as $row) {
echo "<tr><td><b>$row->points</b></td></tr>";
$total_score += $row->points;
}
?>
</table>

/*Final Score Table*/
<table width="960px" border="1">
<tbody>
<tr>
<td width="445px">Total Score (Maximum 125)</td>
<td width="50px"><?php echo $total_score; ?></td>
</tr>
</tbody>
</table>
于 2013-08-29T15:34:46.497 回答