- <?php
- include_once('./conn.inc.php'); //引入資料庫連線檔案
- ?>
- <html>
- <head>
- <title>討論區</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- </head>
- <body>
- <?php
- $sql = "SELECT * FROM `articledata_tab`";
- $result = mysqli_query($conn, $sql); //執行SQL語法
- ?>
- <div style="text-align:center;"><!-- CSS的置中 -->
- <table border="2" style="width:80%;"><!-- CSS的寬度設定 --><!-- width="80%" align="center" -->
- <tr>
- <th>編號</th>
- <th>標題</th>
- <th>點閱數</th>
- <th>回應數</th>
- <th>發文人</th>
- <th>發文IP</th>
- <th>發文日期時間</th>
- </tr>
- <?php
- $no=1; //編號
- while($arr_data = mysqli_fetch_assoc($result)){
- //1. 查詢回應數
- $sql = "SELECT COUNT(`rd_id`) AS `num` FROM `replydata_tab`
- WHERE `rd_ad_id` = '{$arr_data['ad_id']}'";
- $result_reply = mysqli_query($conn, $sql); //執行SQL語法
- $num_reply = mysqli_fetch_assoc($result_reply); //解析 result檔 取得回應數
- //2. 查詢發言人
- $sql = "SELECT `ud_name` FROM `userdata_tab`
- WHERE `ud_id` = '{$arr_data['ad_ud_id']}'";
- //echo $sql;
- $result_userdata = mysqli_query($conn, $sql); //執行SQL語法
- $userdata = mysqli_fetch_assoc($result_userdata); //解析 result檔 取得回應數
-
-
- echo '
- <tr>
- <td>'.($no++).'</td>
- <td><a href="./reply.php?id='.$arr_data['ad_id'].'">'.$arr_data['ad_title'].'</a></td>
- <td>'.$arr_data['ad_view'].'</td>
- <td>'.$num_reply['num'].'</td>
- <td>'.$userdata['ud_name'].'</td>
- <th>'.$arr_data['ad_ip'].'</td>
- <td>'.$arr_data['ad_datetime'].'</td>
- </tr>
- ';
- }
- ?>
- </table>
- </div>
- </body>
- </html>
複製代碼 |