0%

[技能檢定]題組二 步驟17 製作前台問卷列表功能

前台問卷調查雖然也有區分登入前和登入後的不同狀態,但是並沒有限制會員一人只能投一票,因此做完此功能後可以先多投幾票,讓長條圖的效果顯示出來,可以節省評閱的時間。

  1. 建立 /front/que.php 檔案,並撰寫問卷問題列表及會員功能限制
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    <fieldset>
    <legend>目前位置:首頁 > 問卷調查</legend>
    <table>
    <tr>
    <th width="10%">編號</th>
    <th width="60%">問卷題目</th>
    <th width="10%">投票總數</th>
    <th width="10%">結果</th>
    <th width="10%">狀態</th>
    </tr>
    <?php
    //取出所有的問卷主題資料
    $ques=$Que->all(['subject_id'=>0]);
    foreach($ques as $key => $que){
    ?>
    <tr>
    <td><?=$key+1;?></td>
    <td><?=$que['text'];?></td>
    <td><?=$que['vote'];?></td>
    <td><!--連結要加上主題資料的id-->
    <a href='?do=result&id=<?=$que['id'];?>'>結果</a>
    </td>
    <td>
    <?php
    //使用session來判斷使用者登入狀態
    if(isset($_SESSION['user'])){
    echo "<a href='?do=vote&id={$que['id']}'>參與投票</a>";
    }else{
    echo "請先登入";
    }
    ?>
    </td>
    </tr>
    <?php } ?>
    </table>
    </fieldset>