I. 10 sentences
1. do not rely ON the register_global = ON environment. From the day when you have just learned how to configure the php runtime environment and even do not understand the impact of register_global ON/off on yourself, we should be brave enough to set it to OFF.
2. Check how to use error_reporting before writing a program.
3. If you don't understand it, you are right. But you need to check the manual before that.
4. Of course, you need to understand the user manual. When you cannot find the answer in the manual, you should consider the search engine on the network.
5. After learning php + mysql, do not yell at writing forum or XXX. To understand, just learning to write Chinese characters does not mean that you have the ability to write poems.
6. When learning web programming, you should first meet the html friend.
7. If you have some skills, try to answer questions from new users. Don't be complacent if you don't know what you understand. If you drop a "simple, it's a basic thing", you have to go.
8. thinking is a good habit. If you do not write it, you are just a fantasy. There is nothing.
9. Write a program. If you are satisfied, read it again in a week, you may think it should be changed.
10. If you have time, look at other people's programs to find out their own shortcomings or advantages.
Ii. Different requirements
1. good at using "reference", which can directly affect the efficiency of the program.
2. Be good at using a Trielement operator to make the program simpler and more efficient.
For example:
Code:
------------------------------------------------------------------
If ($ data [$ I] [nickname])
{
$ Nickname = $ data [$ I] [nickname];
}
Else
{
$ Nickname = $ data [$ I] [ip];
}
------------------------------------------------------------------
Can be written:
Code:
------------------------------------------------------------------
$ Nickname = $ data [$ I] [nickname]? $ Data [$ I] [nickname]: $ data [$ I] [ip];
------------------------------------------------------------------
3. Be good at organizing if... else... loop
For example:
Code:
------------------------------------------------------------------
$ Ext_name = strtolower (str_replace (".", "", strrchr ($ upfilename ,".")));
If (! Empty ($ type ))
{
If (! Strpos ($ type, $ ext_name ))
{
Echo "Please upload the file of $ type form .";
Exit ();
}
}
------------------------------------------------------------------
The above code should be written as follows:
Code:
------------------------------------------------------------------
$ Ext_name = strtolower (str_replace (".", "", strrchr ($ upfilena
Me ,".")));
If (! ($ Type =) & strpos ($ type, $ ext_name) = false)
{
Echo "Please upload the file of $ type form .";
Exit ();
}
------------------------------------------------------------------
4. Try to clear your code
If it is written like this, it is a headache:
Code:
------------------------------------------------------------------
$ Foo = $ _ post ["foo"];
$ Username = $ _ post ["user"];
$ Group = $ _ POST ["group"];
If ($ group = "wheel "){
$ Username = $ username. "wheel ";
}
------------------------------------------------------------------
The same Code makes it easy to see:
Code:
------------------------------------------------------------------
$ Foo = $ _ post ["foo"];
$ Username = $ _ post ["username"];
$ Group = $ _ POST ["group"];
If ($ group = "wheel ")
{
$ Username = $ username. "wheel ";
}
------------------------------------------------------------------
Of course, you should write it as follows:
Code:
------------------------------------------------------------------
$ Foo = & $ _ POST [foo];
$ Username = $ _ POST ["group"]! = Wheel? $ _ POST ["username"]: $ _ POST ["username"]. wheel;
------------------------------------------------------------------
5. Write a standard mysql statement.
Fields and table names are caused by "'" to avoid the impact of reserved words.
If you see the following SQL query, it will be a headache:
Code:
------------------------------------------------------------------
$ Query = "select 'Flash _ comment '. 'content', 'Flash _ comment '. 'nickname', 'Flash _ comment '. 'date', 'Flash _ comment '. 'IP', 'product '. 'P _ name', 'sgflash '. 'fid' from 'Flash _ comment' left join 'product' on ('Flash _ comment '. 'P _ no' = 'product '. 'P _ no') left join 'sgflash' on ('product'
. 'P _ name' = 'sgflash'. 'f _ name') where 'Flash _ comment'. 'P _ no '! = Order by 'Flash _ comment'. 'date '";
------------------------------------------------------------------
The same query can be written as follows:
Code:
------------------------------------------------------------------
$ Query = "SELECT 'Flash _ comment '. 'content', 'Flash _ comment '. 'nickname', 'Flash _ comment '. 'date', 'Flash _ comment '. 'IP', 'product '. 'P _ name', 'sgflash '. 'fid'
FROM 'Flash _ comment'
Left join 'product' ON ('Flash _ comment '. 'P _ no' = 'product'. 'P _ no ')
Left join 'sgflash 'ON ('product'. 'P _ name' = 'sgflash'. 'f _ name ')
WHERE 'Flash _ comment'. 'P _ no '! =
Order by 'Flash _ comment'. 'date '";