Theoretical basis of debit and credit accounting method. A good basic PHP study note.

WBOY
Release: 2016-07-29 08:36:45
Original
1023 people have browsed it

1. Four representation forms of PHP fragments.
Standard tags:
short tags: script tags:
2. PHP variables and data types
1)                         $variable , variables start with letters, _, There can be no spaces
2) Assignment $variable=value;
3) Weak type, direct assignment, no need to explicitly declare the data type
4) Basic data types: Integer, Double, String, Boolean, Object (object or class), Array (Array)
5) Special data types: Resource (reference to third-party resources (such as database)), Null (empty, uninitialized variable)
3. Operator
1) Assignment operator: =
2) Arithmetic Operations:+,-,*,/,%(molding)
3) Connection operator:, no matter what the operating number is, it is used as string, and the result returns String
4) Combined Assignment Operators =, *=, /=, -=, %=, .=
5) Automatically Incrementing and Decrementing automatic increase and decrease operators:
(1)$variable+=1 <=>$variable++;$variable-=1 <=>$variable-, just like C language, do other operations first, then ++ or -
(2) ++$variable, -$variable, do ++ or - first, then do other operations
6) Comparison operator: = = (left side equals right side), != (the left side is not equal to the right side), = = = (the left side is equal to the right side, and the data type is the same), >=, >, <, <=
7) Logical operators: ||ó or, &&óand, xor (When there is and only one of the left and right sides is true, return true),!
4. Comments:
Single-line comments: //, #
Multi-line comments: /* */
5. Each statement ends with;, and Same as java
6. Define constants: define(“CONSTANS_NAME”,value)
7. Print statement: print, same as c language
8. Process control statement
1) If statement:
(1) if(expression)
{
//code to excute if expression evaluates to true
}
(2)if(expression)
{
}
else
{
}
(3)if(expression1)
{
}
elseif(expression2)
{
}
else
{
}
2)       swich statement
switch (  expression )
{
case result
// execute this if expression results in result1
break;
case result
// execute this if expression results in results2
break;
default:
// execute this if no break statement
// has been encountered hitherto
}
3) ? Operator:
(expression)?returned_if_expression_is_true:returned_if_expression_is_false;
4) while statement:
(1) while (expression)
{

{
// code to be executed
} while (expression);
5) for statement:
for (initialization expression; test expression; modification expression) {
// code to be executed
}
6) break; continue
9、 Write function
1) Define function :
function function_name($argument1,$argument2,…) //Formal parameter
{
//function code here;
}
2) Function call
function_name($argument1,$argument2,…); //Formal parameters
3) Dynamic Function Calls:

;
function sayHello() { //Define the function sayHello
print "hello
";
}
$function_holder = "sayHello"; //Assign the function name to the variable $function_holder
$function_holder( ;

Listing 6.8


$life=42;
function meaningOfLife() {
global $life;
/*Re-declare $life as a global variable here. Accessing global variables within a function must be like this. If the value of the variable is changed within the function, it will be changed in all code fragments*/
print "The meaning of Life is $ live & lt; br & gt; ";
}
Meaningoflife ();
? & gt;
& lt;/body & gt;
& lt;/html & gt; ; T & lt; head & gt;
& lt; title>Listing 6.10


function numberedHeading( $txt ) {
static $num_of_calls = 0;
$num_of_calls++;
print "< ;h1> ;$num_of_calls. $txt";
}
numberedHeading("Widgets"); //When called for the first time, print $num_of_calls value is 1
print("We build a fine range of widgets

");
numberedHeading("Doodads"); /*When called for the first time, print $num_of_calls value is 2, because the variable is static type, static type is resident in memory*/
print("Finest in the world< ;p>");
?>


6) Passing value (value) and passing address (reference):
Passing value: function function_name($argument)
< html>

Listing 6.13


function addFive( $num ) {
$num += 5;
}
$orignum = 10;
addFive( &$orignum );
print( $orignum );
?>


Result: 10
Address: funciton function_name( &$argument)


Listing 6.14


function addFive( &$num ) {
$num += 5; /*What is passed is a reference to the variable $num, so changing the value of the formal parameter $num is actually changing the value stored in the physical memory of the variable $orignum*/
}
$orignum = 10;
addFive( $orignum );
print( $orignum );
?>


Result: 15
7) Create an anonymous function: create_function(' string1','string2'); create_function is a PHP built-in function, specially used to create anonymous functions. It accepts two string parameters, the first is the parameter list, and the second is the body of the function

< ;head>
Listing 6.15


$my_anon = create_function( '$a, $b', 'return $a+$ b;' );
print $my_anon( 3, 9 );
// prints 12
?>


8) Determine whether the function exists: function_exists(function_name), parameters For the function name
10, Use PHP to connect to MySQL
1) Connection: &c
2) Close the connection: mysql_close($conn);
3) Establish connection between the database and the connection: mysql_select_db(database name, connection index);
4 ) will The SQL statement is executed for MySQL: $result = mysql_query($sql, $conn); //Add, delete, modify and query are all like this
5) Retrieve data: Return the number of records: $number_of_rows = mysql_num_rows($result);
Put the records Enter the array: $newArray = mysql_fetch_array($result);
Example:
// open the connection
$conn = mysql_connect("localhost", "joeuser", "somepass");
// pick the database to use
mysql_select_db("testDB",$conn);
// create the SQL statement
$sql = "SELECT * FROM testTable";
// execute the SQL statement
$result = mysql _query($sql, $conn ) or die(mysql_error());
//go through each row in the result set and display data
while ($newArray = mysql_fetch_array($result)) {
// give a name to the fields
$id = $ newArray['id'];
          $testField  =  $newArray['testField']; 
                                                                                                                                                                                            newArray['id'];
?>
11. Accept form elements: $_POST[form element name],
such as ó$_POST[user]
Accept the queryString value in the url (GET method): $ _GET[queryString]
12. Go to other pages: header("Location: http://www.samspublishing.com");
13. String operations:
1) explode("-",str)ósplite in Java
2) str_replace ($str1, $str2, $str3) => $str1 is the string to be found, $str2 is the string to replace, $str3 starts to search and replace from this string
3) substr_replace:
14 , session:
1) Open session: session_start(); // You can also set sessi in php.ini
2) Assign value to session: $_SESSION[session_variable_name]=$variable;
3) Access session: $variable =$_SESSION [session_variable_name];
4) Destroy session: session_destroy();
15. Complete example of display classification:
//connect to database
$conn = mysql_connect("localhost", "joeuser", "somepass ")
or die(mysql_error());
mysql_select_db("testDB",$conn) or die(mysql_error());
$display_block = "

My Categories


Select a category to see its items.

";
//show categories first
$get_cats = "select id, cat_title, cat_desc from
store_categories order by cat_title";
$get_cats_res = mysql_query($get_cats) or die (mysql_error());
if (mysql_num_rows($get_cats_res) < 1) { //If the number of returned record rows is less than 1, it means there is no category
$display_block = "

Sorry, no categories to browse.

";
} else {
while ($cats = mysql_fetch_array($get_cats_res)) { //Put the record into the variable $cats
$cat_id = $cats[id ];
$cat_title = strtoupper(stripslashes($cats[cat_title]));
$cat_desc = stripslashes($cats[cat_desc]);
$display_block .= "

href ="$_SERVER[PHP_SELF][U1] ?cat_id=$cat_id">$cat_title//Click this url to refresh this page. Line 28 reads cat_id and displays the corresponding category. Item

$cat_desc

";
if ($_GET[cat_id] == $cat_id) { //Select a category and see the items below
//get items
$get_items = "select id , item_title, item_price
from store_items where cat_id = $cat_id
order by item_title";
$get_items_res = mysql_query($get_items) or die(mysql_error());
if (mysql_num_rows($get_items_res ) < 1) {
$ display_block = "

Sorry, no items in
this category.

";
} else {
$display_block .= "
    ";
    while ($items = mysql_fetch_array($get_items_res)) {
    $item_id = $items[id];
    $item_title = stripslashes($items[item_title]);
    $item_price = $items[item_price];
    $display_block .= "

  • = "
";
}
}
}
}
?>


My Categories

< ;BODY>



16. PHP connection Access:
$dbc=new com("adodb.connection") ;
$dbc->open("driver=microsoft access driver (*.mdb);dbq=c:member.mdb");
$rs=$dbc->execute("select * from tablename");
$i=0;
while (!$rs->eof){
$i+=1
$fld0=$rs->fields["UserName"];
$fld0=$rs->fields[ "Password"];
....
echo "$fld0->value $fld1->value....";
$rs->movenext();
}
$rs->close();
?>

The above introduces the theoretical basis of the debit and credit accounting method. This is a good basic PHP study note, including the theoretical basis of the debit and credit accounting method. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template