mysql資料匯出並分頁

來源:互聯網
上載者:User

標籤:mit   host   image   localhost   etc   標籤   技術分享   set   ota   

 1 <?php 2 @mysql_connect("localhost","root","")or die; 3 @mysql_select_db("test1")or die; 4 $query = @mysql_query("select * from yonghu")or die; 5 $pagesize = 15;        //設定每頁記錄數 6 $sum = mysql_numrows($query);    //計算總記錄數 7 if($sum%$pagesize == 0) 8     $total = (int)($sum/$pagesize); 9 else 10     $total = (int)($sum/$pagesize)+1;11 12 if(isset($_GET[‘page‘]))13 {14     $p = (int)$_GET[‘page‘];15 }16 else 17 {18     $p = 1;19 }20 21 $start = $pagesize * ($p-1);22 $query = @mysql_query("select * from yonghu limit $start,$pagesize")or die;23 echo "<table border=1><tr align=center><th>使用者名稱</th><th>性別</th><th>出生日期</th><th>郵箱</th></tr>";24 while ($row = mysql_fetch_array($query))25 {26     $username = $row[‘username‘];27     $sex = $row[‘sex‘];28     $birth = $row[‘birth‘];29     $email = $row[‘email‘];30     echo "<tr>";31     echo "<td>{$username}</td>";32     echo "<td>{$sex}</td>";33     echo "<td>{$birth}</td>";34     echo "<td>{$email}</td>";35     echo "</tr>";36 }37 echo "<table>";38 if ($p>1)39 {40     $prev = $p-1;41     echo "<a href = ‘?page=$prev‘>上一頁</a>";42 }43 if($p<$total)44 {45     $next = $p+1;46     echo "<a href = ‘?page=$next‘>下一頁</a>";47 }48 ?>

 

 

該分頁使用的是地址欄的$_GET方式來將值賦給下一頁的<a>標籤裡的連結變數,從而實現了將該值通過

$start = $pagesize * ($p-1);

的關係,成為limit新的位移量。

 1 if(isset($_GET[‘page‘])) 2 { 3     $p = (int)$_GET[‘page‘]; 4 } 5 else  6 { 7     $p = 1; 8 } 9 10 $start = $pagesize * ($p-1);

 

mysql資料匯出並分頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.