Simple paging and batch deletion of PHP code

Source: Internet
Author: 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); // The total number of records.
$ Pagesize = 10; // number of entries displayed per page
If (! Isset ($ _ Get ['page'])
{
$ Page = 1; // determine whether it is the first page
}
Else
{
$ Page = (INT) ($ _ Get ['page']); // obtain the page number.
}
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
/*
* Summary of minor errors:
* 1: <form action = "new_delete.php" method = "Post"> <! -- Only form can be submitted, and table cannot be submitted -->
* 2: mysql_select_db ("ABC", $ conn); // quotation marks are still required for ABC.
* 3: $ result = mysql_query ($ SQL)
* 4: If (isset ($ _ Get ['id']), the hyperlink can only be obtained by get.
* 5: the submission of checkbox and so on depends on the method setting of the form.
* 6: $ SQL = "delete from table_for_page where id = $ id1"; // The $ id1, dollar sign worth noting when referencing variables in Khan PHP !!!
*/
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.