Summary after learning php html javascript

Source: Internet
Author: User

Php Section

Php basic syntax: You can view some websites written by others on the Internet)

1. Create a database connection:

$ Conn = mysql_connect ("localhost", "root", "admin") or die ("cocould not connect ");

Localhost: local host name, root: mysql database account admin: mysql Database Password

Mysql_select_db ("test", $ conn) or die ("cocould not connect :");

Test: Database Name in mysql


2. Get the total number of records in the data table

$ Count = mysql_query ("select count (*) from goods"); // goods table

$ Rs = mysql_fetch_array ($ count );

$ TotalNumber = $ rs [0]; // total number of data records


3. Get data from a data table

The goods table is as follows:

ID NAME PRICE NUMBER


$ Count = mysql_query ("select count (*) from goods ");

$ Row = mysql_fetch_array ($ result );

Echo $ row ["ID"];

To output all the contents of the table, use a while

While ($ row = mysql_fetch_array ($ result )){

Echo $ row ["ID"];

}


4. Solve the Problem of garbled Chinese characters in the database

After the database is connected, add mysql_set_charset ('gbk', $ conn );

For more information, see: http://blog.csdn.net/ACMAIN_CHM/article/details/4174186


5. Obtain the system time

The obtained system time is not Beijing time, so we need to set the city

Date_default_timezone_set (PRC );

Reference: http://www.eoncn.com/article/show/3088.html

The following statement is used to obtain the system time.
$ Curtime = date ('Y-m-d H: I: s', time ());

Reference: http://blog.csdn.net/itzhiren/article/details/1557558


6. Implement tables by PAGE

// Establish a database connection

$ Conn = mysql_connect ("localhost", "root", "admin") or die ("cocould not connect :");

Mysql_select_db ("test", $ conn) or die ("cocould not connect :");




$ PerNumber = 10; // number of records displayed on each page

$ Page = $ _ GET ['page']; // obtain the current page value.

$ Count = mysql_query ("select count (*) from tablename"); // obtain the total number of tablename records

$ Rs = mysql_fetch_array ($ count );

$ TotalNumber = $ rs [0];

$ TotalPage = ceil ($ totalNumber/$ perNumber); // calculate the total number of pages

If ($ totalPage = 0) $ totalPage = 1; // if the table is empty, the total page number is one page by default.

If (! Isset ($ page )){

$ Page = 1;

} // If no value exists, 1 is assigned.



?>




// Pagination ***********************

$ Fenye = "buygoods. php"; // php file name to jump to after page feed

If ($ totalPage! = 1 & $ page! = 1) {// the page number is not equal to 1 and is not the first page. The homepage link is displayed.

?>

? Page = 1 "> Homepage

{

}

If ($ page! = 1 & $ totalPage! = 1) {// the page number is not equal to 1 and is not the first page. The previous page Link is displayed.

?>

? Page = "> Previous Page

}

For ($ I = 1; $ I <= $ totalPage; $ I ++) {// The page is displayed cyclically.

If ($ I = $ page ){

Echo $ I; // no link is set on the current page

} Else {// link for setting non-current page

?>

? Page = ">

}

}

If ($ page <$ totalPage) {// if the page is smaller than the total number of pages, the next page Link is displayed.

?>

? Page = "> Next page

}

If ($ totalPage! = 1 & $ page! = $ TotalPage) {// the page number is not equal to 1 and is not the last page. The [last page] link is displayed.

?>

? Page = "> Last page

}

?>





Html section:

Http://wenku.baidu.com/link? Url = c6xho12fHpg5V2iyS7tJp-0KxzjEmVHnn2OxtkW0iIoYR9Ifyis463pz2R6en40cIBBQkn3TdVz8EwvXjqDQGaZPhLEJItNbG4PWQz7lyl _



Javascript section:

You can get started with more languages.


1. the method that can be used to write html buttons

For more information, see [Account logon and registration page ].


2. You can use regular expressions to determine whether a string meets the requirements.

For details about how to implement the judgment, refer to the following

Var r =/regular expression /;

If (! R. test (number) alert ("warning ");


The following is a common regular expression.

^ [0-9] * [1-9] [0-9] * $ // positive integer

^ (-\ D +) | (0 +) $ // non-positive integer (negative integer + 0)

^-[0-9] * [1-9] [0-9] * $ // negative integer

^ -? \ D + $ // integer

^ \ D + (\. \ d + )? $ // Non-negative floating point number (Positive floating point number + 0)

^ ([0-9] + \. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * \. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ // Positive floating point number

^ (-\ D + (\. \ d + )?) | (0 + (\. 0 + )?)) $ // Non-Positive floating point number (negative floating point number + 0)


Related Article

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.