簡單分頁和大量刪除php代碼

來源:互聯網
上載者:User

<html>
<body>
<form  action="new_delete.php" method="post">
<table  border=2 align="center">
<?php
 include 'conn.php';
$sql="select *from table_for_page";
$result=mysql_query($sql);
$number=mysql_num_rows($result); //共有多少條記錄
$pagesize=10;//每頁顯示條數
if(!isset($_GET['page']))
{
$page=1;//判斷是否為第一頁
}
else 
{
$page=(int)($_GET['page']);//擷取頁碼
}
if($number%$pagesize==0)
{
$total=(int)($number/$pagesize);
}
else 
{
$total=(int)($number/$pagesize)+1;
}

$start=($page-1)*$pagesize;
$sql="select *from table_for_page limit $start ,$pagesize";
$result=mysql_query($sql);
$row=mysql_fetch_row($result);

while($row)
{
?><tr>
<?php 

for($i=0;$i<3;$i++)
{
if($i==0)
echo "<td><input type=\"checkbox\"  name=\"check[]\" value=$row[0]></td>";
echo "<td>$row[$i]</td>";
}
echo "<td><a href=\"new_delete.php?id=$row[0]&page=$page\">delete</a></td>";
       $row=mysql_fetch_row($result);
    ?>

   </tr>
<?php 
}
?>
<tr><td align="center" colspan="9">
<?php 
if($page>1)
{
$prev=$page-1;
echo "<a href=\"page2.php?page=$prev\">$prev</a>";
echo "|";
}
echo $page;
if($page<$total)
{
$next=$page+1;
echo "<a href=\"page2.php?page=$next\">$next</a>";
}
?>
</td></tr>
</table>
<table align="center">
 <tr>
<td><input type="hidden" name="page" value="<?php echo $page;?>"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="submit"></td>
</tr>
</table>
</form>
</body>
</html>

<?php
/*
 * 小錯誤總結:
 * 1:<form action="new_delete.php" method="POST">   <!-- 只有form能提交,table沒有提交的功能 -->
 * 2: mysql_select_db("abc",$conn); //abc還是需要加上引號的
 * 3:$result=mysql_query($sql);定位到這邊的錯誤,往往是$sql語句的問題,一個重要的可能性是沒有串連上conn相應的資料庫
 * 4:if(isset($_GET['id']))超連結方式,超連結只能GET方式擷取
 * 5:checkbox等的提交,取決於所在的form的method的設定
 * 6: $sql="delete from table_for_page where id=$id1"; //汗   php中變數的引用還是要注意的$id1,貨幣符號!!!
 */ 
?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.