Common PHP code Daquan (essential for beginners) is a common basis for some development. For more information, see. 1. connect to the MYSQL database code
$ Connec = mysql_connect ("localhost", "root", "root") or die ("cannot connect to the database server:". mysql_error ());
Mysql_select_db ("liuyanben", $ connec) or die ("The database cannot be selected:". mysql_error ());
Mysql_query ("set names 'gbk '");
?>
2. read the database and implement cyclic output
$ SQL = "select * from liuyan order by ly_id desc ";
$ Conn = mysql_query ($ SQL, $ connec );
While ($ rs = mysql_fetch_array ($ conn )){
?>
Loop content .........
}
?>
3. how to implement paging, including two functions and two calls
1) two functions
// Paging function
Function genpage (& $ SQL, $ page_size = 2)
{
Global $ prepage, $ nextpage, $ pages, $ sums; // out param
$ Page = $ _ GET ["page"];
$ Eachpage = $ page_size;
$ Pagesql = strstr ($ SQL, "from ");
$ Pagesql = "select count (*) as ids". $ pagesql;
$ Conn = mysql_query ($ pagesql) or die (mysql_error ());
If ($ rs = mysql_fetch_array ($ conn) $ sums = $ rs [0];
$ Pages = ceil ($ sums-0.5)/$ eachpage)-1;
$ Pages = $ pages> = 0? $ Pages: 0;
$ Prepage = ($ page> 0 )? $ Page-1: 0;
$ Nextpage = ($ page <$ pages )? $ Page + 1: $ pages;
$ Startpos = $ page * $ eachpage;
$ SQL. = "limit $ startpos, $ eachpage ";
}
// Display the page
Function showpage ()
{
Global $ page, $ pages, $ prepage, $ nextpage, $ queryString; // param from genpage function
$ Shownum = 10/2;
$ Startpage = ($ page >=$ shownum )? $ Page-$ shownum: 0;
$ Endpage = ($ page + $ shownum <= $ pages )? $ Page + $ shownum: $ pages;
Echo "total". ($ pages + 1). "page :";
If ($ page> 0) echo "homepage ";
If ($ startpage> 0)
Echo "...
?";
For ($ I = $ startpage; $ I <= $ endpage; $ I ++)
{
If ($ I = $ page) echo"
[". ($ I + 1)."]";
Else echo "". ($ I + 1 )."";
}
If ($ endpage <$ pages)
Echo"
?...";
If ($ page <$ pages)
Echo "last page ";
}
// Display the page with category
Function showpage1 ()
{
$ Fenlei = $ _ GET ["fenleiid"];
Global $ page, $ pages, $ prepage, $ nextpage, $ queryString; // param from genpage function
$ Shownum = 10/2;
$ Startpage = ($ page >=$ shownum )? $ Page-$ shownum: 0;
$ Endpage = ($ page + $ shownum <= $ pages )? $ Page + $ shownum: $ pages;
Echo "total". ($ pages + 1). "page :";
If ($ page> 0) echo "homepage ";
If ($ startpage> 0)
Echo "...
?";
For ($ I = $ startpage; $ I <= $ endpage; $ I ++)
{
If ($ I = $ page) echo"
[". ($ I + 1)."]";
Else echo "". ($ I + 1 )."";
}
If ($ endpage <$ pages)
Echo"
?...";
If ($ page <$ pages)
Echo "last page}
?>
2) two calls
First
$ SQL = "select * from liuyan order by ly_id desc ";
Genpage ($ SQL); // you only need to add this line to the normal code.
$ Conn = mysql_query ($ SQL, $ connec );
While ($ rs = mysql_fetch_array ($ conn )){
?>
Second
}
?>
Showpage (); // Display Page
?>
Mysql_close ();
?>
4. server-side inclusion
5. how to write a record to the database, and then prompt and jump to the page
$ Ly_title = $ _ POST ["ly_title"];
$ Ly_content = $ _ POST ["ly_content"];
$ Ly_time = $ _ POST ["ly_time"];
$ Ly_author = $ _ POST ["ly_author"];
$ Ly_email = $ _ POST ["ly_email"];
$ SQL = "insert into liuyan (ly_title, ly_content, ly_time, ly_author, ly_email) values ('". $ ly_title. "','". $ ly_content. "','". $ ly_time. "','". $ ly_author. "','". $ ly_email. "')";
Mysql_query ($ SQL, $ connec );
Echo ("
33. open a window to maximize
38. move the mouse over the link
Style = "cursor: hand"
39. how to close the layer
Close layer
40. [close the window]
41. the concave text background is gray
How are you doing?
Don't you want to try it?
Www.lenvo.cn
42. link the table
43. back & close the window
Back: javascript: history. back (1)
Close: javascript: window. close ();
44. if the text is too long, the excessive text will be displayed as a ellipsis.
For example, a line of text is long, and a line in the table cannot be displayed.
45. prohibit copying. drag and select