Only for self-entertainment.
Big guys show mercy under the keyboard. Thank you
About implementing a simple book management system (php native + mysql, simple HTML and CSS)
Realized function
1. Realize the function of borrowing and returning books
2. Realize the login function of different roles for administrator readers
3. Upload and modify books related parameters
Unimplemented features
1. One day before the specified time, it will be reminded after the user logs in.
2. Forcibly lock out users who do not return books and follow-up processing
Table to be created
1. Book list
Primary key id, book title, storage location, price, quantity, picture, introduction
2. Reader list
Primary key id, user name, account number, password, whether to allow books to be borrowed (controlled by the administrator)
3. Administrator table
Primary key id, username, password
4. Borrowing form
Primary key id, book title, quantity (you can judge the number of books borrowed by the user through js, if it is greater than 1, it will not be returned directly, and the user will be warned)
Required page
html login page, registration page
php login page, registration page, book selection page, management book page, borrowing page
How to make the key and difficult points. The book borrowing table. The borrowed book is greater than 1. The user continues to borrow the book. Session and cookie
1. Page making
log in page
form
Two inputs
One submit, one button, two radios
One is responsible for login submission, one is responsible for registration jump
submit to login.php
login.php
Link database
if to determine the radio option
Query matching
if branch
Successful login (open session)
else
Login failed
Jump to the login interface
2 Registration page
Three inputs
One submit two radio
(Duplicate check work is not realized and Xajax is not learned)
if judge radio
The branch decides to write data to the user table or the administrator table
Then jump to the login interface
3 Reader Administrator Interface
php file
Open session
Connect to the database
Paging function:
$page = empty($_GET['page'])? 1 :$_GET['page'];//Set the initial page to 1, otherwise get it through get. Ternary operator, you can also use if...else form
//Connect to the database
$link = mysqli_connect('localhost','root','root');
if(!$link)
{
exit("No");
}
mysqli_set_charset($link,'utf8');
mysqli_select_db($link,'glbook');
//Paging
sql:select count(*) as count from book;//Return the total number of records in the book table, and give the total number of records an alias count
$res=mysqli_query($link,$sql);//Execute statement
$pageres=mysqli_fetch_assoc($res);//Get the total number of records as x
$count = $pageres['count']//Get the value aliased to count
Set each page to display $num = 5
Find the total number of pages $pagecount = ceil($count/$num);//ceil is the php rounding up function, the purpose is to display it on a new page even if there is only one left
Find the offset $pyl = ($page-1)*$num//The current page minus 1, multiplied by the number of items to be displayed on each page is the first parameter in limit. (That is to take data from $ply+1 until $num (the number of items to be displayed per page parameter 2))
sql:select * from book limit $qyl.','.$num; //Limit the number of items per query by limit
$obj = mysqli_query($link,$sql);//Execute query
while打印<table>
while($rows = mysqli_fetch_assoc($obj))//print a row of the table for each row, until the while parameter is 0, assoc can read down row by row
{
code.....
}
$prev = $page -1 ;
$next = $page +1;
Also impose restrictions on $prev and $next, otherwise it will continue to decrease and increase
if($prev<1)
{
$prev = 1;
}
if($next>$pagecount)
{
$next = $pagecount
}
mysqli_close($link);
Realize the function of home page, previous page, next page, and last page //GET transmission
<a href="xxx.php?page=1">S</a>
<a href="xxx.php?page=<?php echo $prev;?>">P</a>
<a href="xxx.php?page=<?php echo $next;?>">N</a>
<a href="xxx.php?page=<?php echo $pagecount;?>">W</a>
//Gently spray, light spray.