<?php 
header("Content-Type: text/html; charset=utf-8");
require_once("connMysql.php");
//預設每頁筆數
$pageRow_records = 6;
//預設頁數
$num_pages = 1;
//若已經有翻頁，將頁數更新
if (isset($_GET['page'])) {
  $num_pages = $_GET['page'];
}
//本頁開始記錄筆數 = (頁數-1)*每頁記錄筆數
$startRow_records = ($num_pages -1) * $pageRow_records;
//未加限制顯示筆數的SQL敘述句
$query_RecBoard = "SELECT * FROM `petition` ORDER BY `petitiontime` DESC";
//加上限制顯示筆數的SQL敘述句，由本頁開始記錄筆數開始，每頁顯示預設筆數
$query_limit_RecBoard = $query_RecBoard." LIMIT ".$startRow_records.", ".$pageRow_records;
//以加上限制顯示筆數的SQL敘述句查詢資料到 $RecBoard 中
$RecBoard = mysql_query($query_limit_RecBoard);
//以未加上限制顯示筆數的SQL敘述句查詢資料到 $all_RecBoard 中
$all_RecBoard = mysql_query($query_RecBoard);
//計算總筆數
$total_records = mysql_num_rows($all_RecBoard);
//計算總頁數=(總筆數/每頁筆數)後無條件進位。
$total_pages = ceil($total_records/$pageRow_records);
?>
<html>
<head>
<title>富山重建‧萬人連線</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style2 {
	font-family: "標楷體";
	font-weight: bold;
	font-size: 24px;
}
.style5 {
	color: #0000FF;
	font-weight: bold;
}
.style8 {
	color: #FF00FF;
	font-weight: bold;
}
body {
	background-color: #FFFFFF;
}
#Layer4 {	position:absolute;
	width:200px;
	height:52px;
	z-index:2;
	left: 277px;
	top: 3px;
}
-->
</style>
</head>
<body>
<div id="Layer4"><img src="images/active.jpg" width="467" height="61" /></div>
<table width="700" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="58" valign="bottom"><p>&nbsp;</p>
      <p>&nbsp;</p>
      <table width="65%">
      <tr>
        <td width="21%"><a href="active.php"><img src="images/ac.gif" width="130" height="30" border="0" /></a></td>
        <td width="22%"><a href="active_p.php"><img src="images/ac_present.gif" width="130" height="30" border="0" /></a></td>
        <td width="26%"><a href="petition.php"><img src="images/ac_petition.gif" width="130" height="30" border="0" /></a></td>
        <td width="31%"><a href="ppost.php"><img src="images/ac_post.gif" width="130" height="30" border="0" /></a></a></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="58"><table align="left" border="0" cellpadding="0" cellspacing="0" width="701">
        <tr align="right">
          <td width="463"><?php if($total_records<=1000 && $total_records>100){;?>
            <img src="images/sl100.png" alt="已經有100位以上的愛心小飛俠囉！" width="45" height="68">
            <?php }elseif($total_records<=3000 && $total_records>1000){?>
            <img src="images/sl100.png" alt="已經有1000位以上的愛心小飛俠囉！" width="45" height="68">
			<img src="images/sl100.png" alt="已經有1000位以上的愛心小飛俠囉！" width="45" height="68">
			<img src="images/sl100.png" alt="已經有1000位以上的愛心小飛俠囉！" width="45" height="68">
			<img src="images/sl100.png" alt="已經有1000位以上的愛心小飛俠囉！" width="45" height="68">
			<img src="images/sl100.png" alt="已經有1000位以上的愛心小飛俠囉！" width="45" height="68">
			<img src="images/sl100.png" alt="已經有1000位以上的愛心小飛俠囉！" width="45" height="68">
			<img src="images/sl100.png" alt="已經有1000位以上的愛心小飛俠囉！" width="45" height="68">
			<img src="images/sl100.png" alt="已經有1000位以上的愛心小飛俠囉！" width="45" height="68">
			<img src="images/sl100.png" alt="已經有1000位以上的愛心小飛俠囉！" width="45" height="68">
			<img src="images/sl100.png" alt="已經有1000位以上的愛心小飛俠囉！" width="45" height="68"><?php }elseif($total_records<=6000 && $total_records>3000){?>
			<img src="images/sl3000.png" alt="已經有3000位以上的愛心小飛俠囉！" width="160" height="83">
			<?php }elseif($total_records<=10000 && $total_records>6000){?>
			<img src="images/sl6000.png" alt="已經有6000位以上的愛心小飛俠囉！" width="224" height="104">
			<?php }elseif($total_records<=20000 && $total_records>10000){?>
			<img src="images/sl10000.png" alt="已經有10000位以上的愛心小飛俠囉！" width="303" height="106">
			<?php }?></td>
          <td width="238"><span class="style2"> 目前連署人數：<?php echo $total_records;?></span></td>
        </tr>
      </table></td>
  </tr>

  <tr>
    <td background="images/taiwan.gif"><div id="mainRegion">
        <?php	while($row_RecBoard=mysql_fetch_assoc($RecBoard)){ ?>
        <table width="80%">
</table>
<table width="65%" border="0" align="center" cellpadding="4" cellspacing="0">
          <tr valign="top">
            <td width="121" align="center"><?php if($row_RecBoard["petitionsex"]=="男"){;?>
              <p><img src="images/lovefly.jpg" alt="我是男生" width="83" height="98">              </p>
              <p>  <span class="style5"><?php echo wordwrap($row_RecBoard["petitionname"]);?></span>
                <?php }else{?>
                <img src="images/lovefly.jpg" alt="我是女生" width="83" height="98">                </p>
              <p><span class="style8"><?php echo wordwrap($row_RecBoard["petitionname"]);?></span>
                <?php }?>
                <br>
              </p></td>
            <td width="317"><p><?php echo wordwrap($row_RecBoard["petitioncontent"]);?></p>
            <p align="right" class="smalltext"><?php echo $row_RecBoard["petitiontime"];?>
              <?php if($row_RecBoard["petitionphone"]!=""){?>
              <?php }?>
</p></td>
          </tr>
          <tr valign="top">
            <td height="1" colspan="2" align="center" background="images/vline.gif"></td>
          </tr>
        </table>
        <?php }?>
        <table width="65%" border="0" align="center" cellpadding="4" cellspacing="0">
          <tr>
            <td width="31%" valign="middle"><p>&nbsp;</p></td>
            <td width="69%" align="right"><p>
                <?php if ($num_pages > 1) { // 若不是第一頁則顯示 ?>
                <a href="?page=1">第一頁</a> | <a href="?page=<?php echo $num_pages-1;?>">上一頁</a> |
                <?php }?>
                <?php if ($num_pages < $total_pages) { // 若不是最後一頁則顯示 ?>
                <a href="?page=<?php echo $num_pages+1;?>">下一頁</a> | <a href="?page=<?php echo $total_pages;?>">最末頁</a>
                <?php }?>
            </p></td>
          </tr>
        </table>
      </div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>
