Have you ever tried the sitemap genertor that provided by google? I have tried it today. But I found it was very hard to use. It needs a lot of requirments, just as following:
The Google Sitemap Generator is a Python script that creates a Sitemap for your site using the Sitemap Protocol. This script can create Sitemaps from URL lists, web server directories, or from access logs. In order to use this script:
You must be able to connect to and run scripts on your web server.
Your web server must have Python 2.2 or later installed.
You must know the command that launches Python. (Generally, this is python, but may vary by installation. For instance, if the web server has two versions of Python installed, the earlier version may be invoked by the command python and the later version may be invoked by the command python2.)
You must know the directory path to your site. If your web server hosts one site, this may be a path such as var/www/html. If you have a virtual server that hosts multiple sites, this may be a path such as home/virtual/site1/fst/var/www/html.
You must be able to upload files to your web server (for instance, using FTP).
If you will be generating a list of URLs based on access logs, you must know the encoding used for those logs and the complete path to them.
If you aren't sure about any of this, you can check with your web hosting company.
I don't think all the host company provides such kind of service. So I think I can generate the sitemap on my local computer and then upload to the server. May be you have the same idea with me. I installed the Python on my local computer and run the sitemap_gen.py. It has a lot of configuration to make, I have tried many times to make it correct. But no success results, seems it can not crawl the target site automatically. It always generate only one url(the target url) in the sitemap.xml. What's your experience? Maybe it is not a good tool for some webmasters(just as me).
There are many online free sitemap generators. Most of them are free for sites that have lower than 5,000 links. They are good enough for small websites. But if you have a site that has more than 10,000 links, what will you do? To use their payed service? I don't think this is a good choice for some websites with a little investment.
I searched on google and found a good free software - VIGOS Gsitemap . VIGOS Gsitemap is a 100% FREE, easy-to-use but versatile Windows sitemap generator tool to help webmasters and website owners to create, edit and submit sitemap information in adherence to the Google Sitemaps protocol.
It's a good tool for generating google sitemap. But I suggest the author to improve one thing, when the user clicks the shut button, it should pop up a warning window to let the user to ensure shut down. I have shutted the soft two times by mistake while it was running. All the crawled data were lost every time, I had to start from zero. It took a lot of time. If it has the warning function when shut down, it will be helpful.
Sunday, December 16, 2007
Free Google Sitemap Generator Software(Based on Windows)
Wednesday, December 05, 2007
My experience of optimizing from PR 0 to PR 4.
I am not a professor in SEO, but I have got my own experience in opimizing a site from pr 0 to pr 4. So, I'd like to write something here, hope it will be the open door for the new beginners. I forget to reveal that I am a programmer in PHP, maybe the experience in programming help me a little. But it is not an important factor, I think a little understanding of HTML is enough. But if you have a strong background in website building or programming, it will be more helpful. Ok, let's start.
1. You should understand what your site focus on. What are your target visitors? Choose the best keywords that describe your site accurately. I think this is very important. How dose google or other search engines find your site? They are not so smart as you think. The only thing they can do is text matching. If your site have the word that the visitor is searching, google or other search engines will search in their cached files. If they find a match, then return the match as the search result. So, if you don't have the word that the visistor is searching for, google or other search engines will not find you. Obviously, your site shoule be cached by them first.
How to find a good keyword? I give you two links which I usually use.
a> http://inventory.overture.com/
b> https://adwords.google.com/select/KeywordToolExternal
Just use these two links to search the product or some thing else that your site focus on. You will find the most popular keywords that surfers use and also the search times happen in some months.
2. When you finish the first step, I think you will have a lot of keywords in your hands. Ok, how to put them into your site content? Just write them as comma separated? No, do not do that. You should write soemthing to smoothly include these words. Put this full keywords paragraph in the beginning of your page. Remember the search engine robot reads your page from the top to the bottom, top will be much better than the bottom. But it is not an key factor. Have the keyword is the most important thing.
3. Start building links. You can find some good forums to exchange links with others. I recommend 2 as following which are usually used by myself.
a> http://www.webmaster-talk.com/
b> http://forums.digitalpoint.com/
Do not forget to use signature. It is a good way to give a back link to your site whenever you submit a post. When you start building links for a new site. It is very hard to find a partner to exchange links. Don't worry, keep on posting with signature that links to your site. Your website will be soonly cached by search engines in the following weeks. After that you can tell someone that you'd like to exchange a link with him on your cached pages. They will be much happier to do so.
Although content related links are much better than other links. Some content related website may not want to exchange a link with a NO PR website. I think for a new website you needn't to pursue content related links. Any link(HAVEN'T BEEN PUNISHED BY SEARCH ENGINES) is OK. After you get some PR, start building content related links. Keep on exchanging links, the large quantity of back links you get, the higher PR and higher position your site will gain.
Hope the above 3 will give you some open minds in SEO. They are not new but are my own real experience. I'd like to share with you. Do you have anything to share? Do not hesitate to give a comment. Thanks.
1. You should understand what your site focus on. What are your target visitors? Choose the best keywords that describe your site accurately. I think this is very important. How dose google or other search engines find your site? They are not so smart as you think. The only thing they can do is text matching. If your site have the word that the visitor is searching, google or other search engines will search in their cached files. If they find a match, then return the match as the search result. So, if you don't have the word that the visistor is searching for, google or other search engines will not find you. Obviously, your site shoule be cached by them first.
How to find a good keyword? I give you two links which I usually use.
a> http://inventory.overture.com/
b> https://adwords.google.com/select/KeywordToolExternal
Just use these two links to search the product or some thing else that your site focus on. You will find the most popular keywords that surfers use and also the search times happen in some months.
2. When you finish the first step, I think you will have a lot of keywords in your hands. Ok, how to put them into your site content? Just write them as comma separated? No, do not do that. You should write soemthing to smoothly include these words. Put this full keywords paragraph in the beginning of your page. Remember the search engine robot reads your page from the top to the bottom, top will be much better than the bottom. But it is not an key factor. Have the keyword is the most important thing.
3. Start building links. You can find some good forums to exchange links with others. I recommend 2 as following which are usually used by myself.
a> http://www.webmaster-talk.com/
b> http://forums.digitalpoint.com/
Do not forget to use signature. It is a good way to give a back link to your site whenever you submit a post. When you start building links for a new site. It is very hard to find a partner to exchange links. Don't worry, keep on posting with signature that links to your site. Your website will be soonly cached by search engines in the following weeks. After that you can tell someone that you'd like to exchange a link with him on your cached pages. They will be much happier to do so.
Although content related links are much better than other links. Some content related website may not want to exchange a link with a NO PR website. I think for a new website you needn't to pursue content related links. Any link(HAVEN'T BEEN PUNISHED BY SEARCH ENGINES) is OK. After you get some PR, start building content related links. Keep on exchanging links, the large quantity of back links you get, the higher PR and higher position your site will gain.
Hope the above 3 will give you some open minds in SEO. They are not new but are my own real experience. I'd like to share with you. Do you have anything to share? Do not hesitate to give a comment. Thanks.
Monday, August 13, 2007
Google starts to sell additional space for Gmail users
Google now offers a way to purchase more storage space to use with some Google services (currently Gmail and Picasa Web Albums). This extra storage acts as overflow when you run out of free storage space in either service. If you've filled your free storage (2.8 GB and counting for Gmail or 1 GB for Picasa Web Albums), you'll automatically use your purchased space to store more pictures and messages up to your new storage limit.
Your shared storage space will be used by whatever service needs it. Picasa's free storage is for photos only, and Gmail's is just for Gmail messages, but the shared storage can be all photos, all messages or a mix of both. You can't set aside shared storage space for one service - it will be used by any service that's over its free storage quota on a first-come, first-served basis.
To purchase more storage, visit https://www.google.com/accounts/PurchaseStorage.
To see how much storage you're using, visit https://www.google.com/accounts/ManageStorage.
Sunday, August 12, 2007
How to paste good formatted php source code on blogger?
Several days ago, I just wanted to paste some php codes on this blog. But the codes I pasted was ugly. Then I decided to write something to format the looking. It is finished today.
The formatted codes:
Two steps to paste your nice looking php code on your blog.
1. Visit http://phpgoogle.awardspace.com.
2. Submit your code.
3. Copy and paste the HTML source code to your blog.
Yeah, it's very easy.
And the mechanism is very easy too. I just use PHP's Built-in Source Highlighter - highlight_string(). You can read more about it on clicking the link.
I make the online demo to make the thing easy and convenient. Hope it will be useful for you.
The formatted codes:
<?php
//creates a unique id with the 'about' prefix
$a = uniqid(about);
echo $a;
echo "<br>";
//creates a longer unique id with the 'about' prefix
$b = uniqid (about, true);
echo $b;
echo "<br>";
//creates a unique ID with a random number as a prefix - more secure than a static prefix
$c = uniqid (rand(), true);
echo $c;
echo "<br>";
//this md5 encrypts the username from above, so its ready to be stored in your database
$md5c = md5($c);
echo $md5c;
echo "<br>";
?>
//creates a unique id with the 'about' prefix
$a = uniqid(about);
echo $a;
echo "<br>";
//creates a longer unique id with the 'about' prefix
$b = uniqid (about, true);
echo $b;
echo "<br>";
//creates a unique ID with a random number as a prefix - more secure than a static prefix
$c = uniqid (rand(), true);
echo $c;
echo "<br>";
//this md5 encrypts the username from above, so its ready to be stored in your database
$md5c = md5($c);
echo $md5c;
echo "<br>";
?>
Two steps to paste your nice looking php code on your blog.
1. Visit http://phpgoogle.awardspace.com.
2. Submit your code.
3. Copy and paste the HTML source code to your blog.
Yeah, it's very easy.
And the mechanism is very easy too. I just use PHP's Built-in Source Highlighter - highlight_string(). You can read more about it on clicking the link.
I make the online demo to make the thing easy and convenient. Hope it will be useful for you.
Saturday, August 04, 2007
Four ways to generate unique id by PHP
1. Using uniqid() function
2. Using current time + IP style
3. Generate custom length unique id
4. Generate XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX style unique id, (8 letters)-(4 letters)-(4 letters)-(4 letters)-(12 letters)
<?php
//creates a unique id with the 'about' prefix
$a = uniqid(about);
echo $a;
echo "<br>";
//creates a longer unique id with the 'about' prefix
$b = uniqid (about, true);
echo $b;
echo "<br>";
//creates a unique ID with a random number as a prefix - more secure than a static prefix
$c = uniqid (rand(), true);
echo $c;
echo "<br>";
//this md5 encrypts the username from above, so its ready to be stored in your database
$md5c = md5($c);
echo $md5c;
echo "<br>";
?>
//creates a unique id with the 'about' prefix
$a = uniqid(about);
echo $a;
echo "<br>";
//creates a longer unique id with the 'about' prefix
$b = uniqid (about, true);
echo $b;
echo "<br>";
//creates a unique ID with a random number as a prefix - more secure than a static prefix
$c = uniqid (rand(), true);
echo $c;
echo "<br>";
//this md5 encrypts the username from above, so its ready to be stored in your database
$md5c = md5($c);
echo $md5c;
echo "<br>";
?>
2. Using current time + IP style
<?php
//You can also use $stamp = strtotime ("now"); But I think date("Ymdhis") is easier to understand.
$stamp = date("Ymdhis");
$ip = $_SERVER['REMOTE_ADDR'];
$orderid = "$stamp-$ip";
$orderid = str_replace(".", "", "$orderid");
echo($orderid);
echo "<br>";
?>
//You can also use $stamp = strtotime ("now"); But I think date("Ymdhis") is easier to understand.
$stamp = date("Ymdhis");
$ip = $_SERVER['REMOTE_ADDR'];
$orderid = "$stamp-$ip";
$orderid = str_replace(".", "", "$orderid");
echo($orderid);
echo "<br>";
?>
3. Generate custom length unique id
<?php
//set the random id length
$random_id_length = 10;
//generate a random id encrypt it and store it in $rnd_id
$rnd_id = crypt(uniqid(rand(),1));
//to remove any slashes that might have come
$rnd_id = strip_tags(stripslashes($rnd_id));
//Removing any . or / and reversing the string
$rnd_id = str_replace(".","",$rnd_id);
$rnd_id = strrev(str_replace("/","",$rnd_id));
//finally I take the first 10 characters from the $rnd_id
$rnd_id = substr($rnd_id,0,$random_id_length);
echo "Random Id: $rnd_id" ;
echo "<br>";
?>
//set the random id length
$random_id_length = 10;
//generate a random id encrypt it and store it in $rnd_id
$rnd_id = crypt(uniqid(rand(),1));
//to remove any slashes that might have come
$rnd_id = strip_tags(stripslashes($rnd_id));
//Removing any . or / and reversing the string
$rnd_id = str_replace(".","",$rnd_id);
$rnd_id = strrev(str_replace("/","",$rnd_id));
//finally I take the first 10 characters from the $rnd_id
$rnd_id = substr($rnd_id,0,$random_id_length);
echo "Random Id: $rnd_id" ;
echo "<br>";
?>
4. Generate XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX style unique id, (8 letters)-(4 letters)-(4 letters)-(4 letters)-(12 letters)
<?php
// Generate Guid
function NewGuid() {
$s = strtoupper(md5(uniqid(rand(),true)));
$guidText =
substr($s,0,8) . '-' .
substr($s,8,4) . '-' .
substr($s,12,4). '-' .
substr($s,16,4). '-' .
substr($s,20);
return $guidText;
}
// End Generate Guid
$Guid = NewGuid();
echo $Guid;
echo "<br>";
?>
// Generate Guid
function NewGuid() {
$s = strtoupper(md5(uniqid(rand(),true)));
$guidText =
substr($s,0,8) . '-' .
substr($s,8,4) . '-' .
substr($s,12,4). '-' .
substr($s,16,4). '-' .
substr($s,20);
return $guidText;
}
// End Generate Guid
$Guid = NewGuid();
echo $Guid;
echo "<br>";
?>
Friday, August 03, 2007
reach out to sb...
reach out to sb (mainly US) = to try to communicate with a person or a group of people, usually in order to help or involve them eg The new mayor is reaching out to the local community to involve them in his plans for the city.
Wednesday, August 01, 2007
Do you need a beautiful email icon?
While I am surfing on the web today, I found a site can easily generate Email icon according to your Email service provider. Very funny...
They accept almost every commonly used email service provider. What make me astonished is that QQ.com is listed. It's an IM that very commonly used in China. Almost everyone that surfs the web has a QQ number.
You can have your own email icon put on your blogs or your own websites.
Have fun...
Saturday, March 24, 2007
Link Building Tips and Optimize the Site
-offer a poll on your blog-offer a contests on you website
-create a interactive tool dealing with your products online
-write controversial or newsworthy content
-offer resourceful content-offer humorous content
-give something away for free
-create widgets
-create a interactive tool dealing with your products online
-write controversial or newsworthy content
-offer resourceful content-offer humorous content
-give something away for free
-create widgets
Tuesday, February 13, 2007
How to recover a website from the cache of Google, Internet Archive, Yahoo, MSN
I tried to change several websites by code.I meant to change some pages automatically for they had the same problem.But when the program finished to do so, it was not the result I expected. All the PHP files on the sever were changed to size 0.It's a bad day...Maybe it's something wrong with the server.I just called the server company and asked if they can recover all these size 0 files.They told me it's impposble, they did not have back-ups.What a bad day...bad severice...What should I do?I just thought something about google cache.All of these websites were indexed by Google, Internet Archive, Yahoo, MSN.Can I recover them from these caches?Really a good idea.But how to?I know it's possible to visit all the caches and download the cache files manually.But it's really a large project.I don't want to do this.Maybe I am very lazy.So I go to google for more information.Suddenly Google take me to Warrick, my savior, it's a perl program which is writen by Frank McCown. Soonly I learned how to use it and went to recover my site.The program is very powerful, but the recovery time may be a little long, but it's OK.Really Thanks Frank McCown, thanks very much for good research...
Have you met the same problem with me?Hope it will help you...Good Luck...
Have you met the same problem with me?Hope it will help you...Good Luck...
Monday, February 12, 2007
Choosing a page encoding
Choosing a page encoding Choose UTF-8 or another Unicode encoding for all content.
When selecting a page encoding, consider both current and future localization requirements, and the benefits of using the same encoding across all pages and all languages. These considerations make the use of Unicode an attractive choice for the following reasons:
Unicode supports many languages, enabling the use of a single encoding across all pages and forms, regardless of language.
Unicode allows many more languages to be mixed on a single page than almost any other choice. If the set of languages to be represented on a single page cannot be represented directly by any single native encoding (such as ISO-8859-1, Shift-JIS, etc.), then Unicode is almost certainly the best choice.
For dynamically-generated pages, a single encoding for all pages eliminates the need for server-side logic to determine the character encoding for each page served.
For interactive applications using forms, a single encoding eliminates the need for server-side logic to determine the character encoding of incoming form data.
Unicode enables a form in one language (e.g. English) to accept input in a different language (e.g. Chinese).
Unicode (UTF-8) forms will be easier to migrate to XForms.
UTF-8 and UTF-16 are both Unicode encodings. Since support for Unicode is currently limited to UTF-8 in many user agents, UTF-8 is usually the appropriate Unicode encoding. However, as user agent support for UTF-16 expands, UTF-16 will become an increasingly viable alternative.
Although there are other multi-script encodings (such as ISO-2022 and GB18030), Unicode generally provides the best combination of user agent and script support.
If you don't use a Unicode encoding, select an encoding that best supports the languages / characters to be included in the page text.
There are some situations where selecting a Unicode encoding is not practical. If content is encoded in a native encoding (legacy content or content originating from an external source) and the system lacks functionality for converting content between encodings, Unicode may greatly complicate implementation. If such a site is only required to serve single-script pages (containing languages that can be represented by a single native encoding), then the cost of using a Unicode encoding may outweigh the benefits. In this case, a native encoding (such as ISO-8859-1, Shift-JIS, etc.) may be a better choice.
Be sure to select an encoding that covers most of the characters required for the content, and (if it is a form) all of the characters that must be accepted as input.
Check that user agents (all agents that must render the page) adequately support the page encoding that you have selected. If not, you might need to use a more widely supported encoding to achieve an adequate degree of user agent support.
Not all user agents support all page encodings, so it is important to understand which user agents must be able to render the page, and be sure that they have adequate support for the page encoding you have selected.
In general, user agents are most likely to support the commonly-used native character encodings for the major languages used on the web. Support for less commonly used encodings depends on the user agent. Older user agents, or user agents that operate under severe memory limitations, may not support UTF-8.
It is important to note that support for a given encoding does not necessarily imply support for all writing systems that encoding supports. For example, a user agent might support UTF-8, but not correctly display bidirectional Arabic text encoded in UTF-8. To display a page correctly, a user agents must support both the page encoding and the writing system.
When selecting a page encoding, consider both current and future localization requirements, and the benefits of using the same encoding across all pages and all languages. These considerations make the use of Unicode an attractive choice for the following reasons:
Unicode supports many languages, enabling the use of a single encoding across all pages and forms, regardless of language.
Unicode allows many more languages to be mixed on a single page than almost any other choice. If the set of languages to be represented on a single page cannot be represented directly by any single native encoding (such as ISO-8859-1, Shift-JIS, etc.), then Unicode is almost certainly the best choice.
For dynamically-generated pages, a single encoding for all pages eliminates the need for server-side logic to determine the character encoding for each page served.
For interactive applications using forms, a single encoding eliminates the need for server-side logic to determine the character encoding of incoming form data.
Unicode enables a form in one language (e.g. English) to accept input in a different language (e.g. Chinese).
Unicode (UTF-8) forms will be easier to migrate to XForms.
UTF-8 and UTF-16 are both Unicode encodings. Since support for Unicode is currently limited to UTF-8 in many user agents, UTF-8 is usually the appropriate Unicode encoding. However, as user agent support for UTF-16 expands, UTF-16 will become an increasingly viable alternative.
Although there are other multi-script encodings (such as ISO-2022 and GB18030), Unicode generally provides the best combination of user agent and script support.
If you don't use a Unicode encoding, select an encoding that best supports the languages / characters to be included in the page text.
There are some situations where selecting a Unicode encoding is not practical. If content is encoded in a native encoding (legacy content or content originating from an external source) and the system lacks functionality for converting content between encodings, Unicode may greatly complicate implementation. If such a site is only required to serve single-script pages (containing languages that can be represented by a single native encoding), then the cost of using a Unicode encoding may outweigh the benefits. In this case, a native encoding (such as ISO-8859-1, Shift-JIS, etc.) may be a better choice.
Be sure to select an encoding that covers most of the characters required for the content, and (if it is a form) all of the characters that must be accepted as input.
Check that user agents (all agents that must render the page) adequately support the page encoding that you have selected. If not, you might need to use a more widely supported encoding to achieve an adequate degree of user agent support.
Not all user agents support all page encodings, so it is important to understand which user agents must be able to render the page, and be sure that they have adequate support for the page encoding you have selected.
In general, user agents are most likely to support the commonly-used native character encodings for the major languages used on the web. Support for less commonly used encodings depends on the user agent. Older user agents, or user agents that operate under severe memory limitations, may not support UTF-8.
It is important to note that support for a given encoding does not necessarily imply support for all writing systems that encoding supports. For example, a user agent might support UTF-8, but not correctly display bidirectional Arabic text encoded in UTF-8. To display a page correctly, a user agents must support both the page encoding and the writing system.
Saturday, February 10, 2007
Notes for learing SQL(3)
14. The SELECT INTO Statement
The SELECT INTO statement is most often used to create backup copies of tables or for archiving records.
15. SQL CREATE VIEW Statement
A view is a virtual table based on the result-set of a SELECT statement.
What is a View?In SQL, a VIEW is a virtual table based on the result-set of a SELECT statement.
A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database. You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if the data were coming from a single table.
Note: The database design and structure will NOT be affected by the functions, where, or join statements in a view.
Very hard to understand these two, need to learn more and do more exercises...
The SELECT INTO statement is most often used to create backup copies of tables or for archiving records.
15. SQL CREATE VIEW Statement
A view is a virtual table based on the result-set of a SELECT statement.
What is a View?In SQL, a VIEW is a virtual table based on the result-set of a SELECT statement.
A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database. You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if the data were coming from a single table.
Note: The database design and structure will NOT be affected by the functions, where, or join statements in a view.
Very hard to understand these two, need to learn more and do more exercises...
Friday, February 09, 2007
Notes for learing SQL(2)
9. Create Index
Indices are created in an existing table to locate rows more quickly and efficiently. It is possible to create an index on one or more columns of a table, and each index is given a name. The users cannot see the indexes, they are just used to speed up queries.
Note: Updating a table containing indexes takes more time than updating a table without, this is because the indexes also need an update. So, it is a good idea to create indexes only on columns that are often used for a search.
CREATE INDEX index_nameON table_name (column_name)
10. Truncate a Table
What if we only want to get rid of the data inside a table, and not the table itself? Use the TRUNCATE TABLE command (deletes only the data inside the table):
TRUNCATE TABLE table_name
11. ALTER TABLE
The ALTER TABLE statement is used to add or drop columns in an existing table.
ALTER TABLE table_name ADD column_name datatype
ALTER TABLE table_name DROP COLUMN column_name
Note: Some database systems don't allow the dropping of a column in a database table (DROP COLUMN column_name).
12. SQL Functions
SQL has a lot of built-in functions for counting and calculations.
Function SyntaxThe syntax for built-in SQL functions is:
SELECT function(column) FROM table
Types of Functions
There are several basic types and categories of functions in SQL. The basic types of functions are:
Aggregate Functions - Aggregate functions operate against a collection of values, but return a single value.
Scalar functions - Scalar functions operate against a single value, and return a single value based on the input value.
13. SQL GROUP BY and HAVING
GROUP BY...GROUP BY... was added to SQL because aggregate functions (like SUM) return the aggregate of all column values every time they are called, and without the GROUP BY function it was impossible to find the sum for each individual group of column values.
The syntax for the GROUP BY function is:
SELECT column,SUM(column) FROM table GROUP BY column
HAVING...HAVING... was added to SQL because the WHERE keyword could not be used against aggregate functions (like SUM), and without HAVING... it would be impossible to test for result conditions.
The syntax for the HAVING function is:
SELECT column,SUM(column) FROM tableGROUP BY columnHAVING SUM(column) condition value
Indices are created in an existing table to locate rows more quickly and efficiently. It is possible to create an index on one or more columns of a table, and each index is given a name. The users cannot see the indexes, they are just used to speed up queries.
Note: Updating a table containing indexes takes more time than updating a table without, this is because the indexes also need an update. So, it is a good idea to create indexes only on columns that are often used for a search.
CREATE INDEX index_nameON table_name (column_name)
10. Truncate a Table
What if we only want to get rid of the data inside a table, and not the table itself? Use the TRUNCATE TABLE command (deletes only the data inside the table):
TRUNCATE TABLE table_name
11. ALTER TABLE
The ALTER TABLE statement is used to add or drop columns in an existing table.
ALTER TABLE table_name ADD column_name datatype
ALTER TABLE table_name DROP COLUMN column_name
Note: Some database systems don't allow the dropping of a column in a database table (DROP COLUMN column_name).
12. SQL Functions
SQL has a lot of built-in functions for counting and calculations.
Function SyntaxThe syntax for built-in SQL functions is:
SELECT function(column) FROM table
Types of Functions
There are several basic types and categories of functions in SQL. The basic types of functions are:
Aggregate Functions - Aggregate functions operate against a collection of values, but return a single value.
Scalar functions - Scalar functions operate against a single value, and return a single value based on the input value.
13. SQL GROUP BY and HAVING
GROUP BY...GROUP BY... was added to SQL because aggregate functions (like SUM) return the aggregate of all column values every time they are called, and without the GROUP BY function it was impossible to find the sum for each individual group of column values.
The syntax for the GROUP BY function is:
SELECT column,SUM(column) FROM table GROUP BY column
HAVING...HAVING... was added to SQL because the WHERE keyword could not be used against aggregate functions (like SUM), and without HAVING... it would be impossible to test for result conditions.
The syntax for the HAVING function is:
SELECT column,SUM(column) FROM tableGROUP BY columnHAVING SUM(column) condition value
Thursday, February 08, 2007
Notes for learing SQL(1)
1. Some Abbreviations
SQL - Sturcture Query Language
DML - Data Manipulation Language (Part of SQL)
SELECT - extracts data from a database table
UPDATE - updates data in a database table
DELETE - deletes data from a database table
INSERT INTO - inserts new data into a database table
DDL - Data Definition Language (Part of SQL)
CREATE TABLE - creates a new database table
ALTER TABLE - alters (changes) a database table
DROP TABLE - deletes a database table
CREATE INDEX - creates an index (search key) DROP INDEX - deletes an index
2. Using Quotes
SQL uses single quotes around text values (most database systems will also accept double quotes). Numeric values should not be enclosed in quotes.
3. The LIKE condition
A "%" sign can be used to define wildcards (missing letters in the pattern) both before and after the pattern.
SELECT * FROM Persons WHERE FirstName LIKE 'O%'
//return persons with first names that start with an 'O'
SELECT * FROM Persons WHERE FirstName LIKE '%a'
//return persons with first names that end with an 'a'
SELECT * FROM Persons WHERE FirstName LIKE '%la%'
//return persons with first names that contain the pattern 'la'
4. IN
The IN operator may be used if you know the exact value you want to return for at least one of the columns.
SELECT column_name
FROM table_name
WHERE column_name IN (value1,value2,..)
5. BETWEEN ... AND
The BETWEEN ... AND operator selects a range of data between two values. These values can be numbers, text, or dates.
SELECT column_name
FROM table_name
WHERE column_name BETWEEN value1 AND value2
To display values outside the range, use the NOT operator:
SELECT column_name FROM table_name WHERE column_name NOT BETWEEN value1 AND value2
IMPORTANT! The BETWEEN...AND operator is treated differently in different databases.Whether the return set include or exclude value1 or value2, you need to check your database.
6. SQL alias
With SQL, aliases can be used for column names and table names.
SELECT column AS column_alias FROM table SELECT column FROM table AS table_alias
7. SQL JOIN
INNER JOIN
SELECT field1, field2, field3
FROM first_table
INNER JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield
The INNER JOIN returns all rows from both tables where there is a match. If there are rows in first_table that do not have matches in second_table, those rows will not be listed.
LEFT JOIN
SELECT field1, field2, field3
FROM first_table
LEFT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield
The LEFT JOIN returns all the rows from the first_table, even if there are no matches in the second_table. If there are rows in first_table that do not have matches in second_table, those rows also will be listed.
RIGHT JOIN
SELECT field1, field2, field3
FROM first_table
RIGHT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield
The RIGHT JOIN returns all the rows from the second_table, even if there are no matches in the first_table. If there had been any rows in second_table that did not have matches in first_table, those rows also would have been listed
8. SQL UNION and UNION ALL
SQL Statement 1
UNION
SQL Statement 2
The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type.
Note: With UNION, only distinct values are selected.
SQL Statement 1
UNION ALL
SQL Statement 2
The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values(include the same values).
SQL - Sturcture Query Language
DML - Data Manipulation Language (Part of SQL)
SELECT - extracts data from a database table
UPDATE - updates data in a database table
DELETE - deletes data from a database table
INSERT INTO - inserts new data into a database table
DDL - Data Definition Language (Part of SQL)
CREATE TABLE - creates a new database table
ALTER TABLE - alters (changes) a database table
DROP TABLE - deletes a database table
CREATE INDEX - creates an index (search key) DROP INDEX - deletes an index
2. Using Quotes
SQL uses single quotes around text values (most database systems will also accept double quotes). Numeric values should not be enclosed in quotes.
3. The LIKE condition
A "%" sign can be used to define wildcards (missing letters in the pattern) both before and after the pattern.
SELECT * FROM Persons WHERE FirstName LIKE 'O%'
//return persons with first names that start with an 'O'
SELECT * FROM Persons WHERE FirstName LIKE '%a'
//return persons with first names that end with an 'a'
SELECT * FROM Persons WHERE FirstName LIKE '%la%'
//return persons with first names that contain the pattern 'la'
4. IN
The IN operator may be used if you know the exact value you want to return for at least one of the columns.
SELECT column_name
FROM table_name
WHERE column_name IN (value1,value2,..)
5. BETWEEN ... AND
The BETWEEN ... AND operator selects a range of data between two values. These values can be numbers, text, or dates.
SELECT column_name
FROM table_name
WHERE column_name BETWEEN value1 AND value2
To display values outside the range, use the NOT operator:
SELECT column_name FROM table_name WHERE column_name NOT BETWEEN value1 AND value2
IMPORTANT! The BETWEEN...AND operator is treated differently in different databases.Whether the return set include or exclude value1 or value2, you need to check your database.
6. SQL alias
With SQL, aliases can be used for column names and table names.
SELECT column AS column_alias FROM table SELECT column FROM table AS table_alias
7. SQL JOIN
INNER JOIN
SELECT field1, field2, field3
FROM first_table
INNER JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield
The INNER JOIN returns all rows from both tables where there is a match. If there are rows in first_table that do not have matches in second_table, those rows will not be listed.
LEFT JOIN
SELECT field1, field2, field3
FROM first_table
LEFT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield
The LEFT JOIN returns all the rows from the first_table, even if there are no matches in the second_table. If there are rows in first_table that do not have matches in second_table, those rows also will be listed.
RIGHT JOIN
SELECT field1, field2, field3
FROM first_table
RIGHT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield
The RIGHT JOIN returns all the rows from the second_table, even if there are no matches in the first_table. If there had been any rows in second_table that did not have matches in first_table, those rows also would have been listed
8. SQL UNION and UNION ALL
SQL Statement 1
UNION
SQL Statement 2
The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type.
Note: With UNION, only distinct values are selected.
SQL Statement 1
UNION ALL
SQL Statement 2
The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values(include the same values).
Tuesday, February 06, 2007
About FULLTEXT
I am learning "Beginning PHP5 Apache and MySQL Web Development" now.It's really a good book for PHP beginners.If you are just start now, I strongly recommend you to read this book.Very easy to understand, so many examples...www.wrox.com
I am reading chapter 16 - a bulletin board.While I am trying to run the setup.php, a problem jump out... "The used table type doesn't support FULLTEXT indexes".This is the first time I meet this kind MySQL problem.I searched on Google and got the answer.
"This message appears when the database server is configured to use another table type than MyISAM."
original code -
CREATE TABLE forum_posts (
id int(11) NOT NULL auto_increment,
topic_id int(11) NOT NULL default '0',
forum_id int(11) NOT NULL default '0',
author_id int(11) NOT NULL default '0',
update_id int(11) NOT NULL default '0',
date_posted datetime NOT NULL default '0000-00-00 00:00:00',
date_updated datetime NOT NULL default '0000-00-00 00:00:00',
subject varchar(255) NOT NULL default '',
body mediumtext NOT NULL,
PRIMARY KEY (id),
KEY IdxArticle (forum_id,topic_id,author_id,date_posted),
FULLTEXT KEY IdxText (subject,body)
) TYPE=MyISAM //add the red code to correct the mistake.
If you meet the same problem, hope the article can help you.
I am reading chapter 16 - a bulletin board.While I am trying to run the setup.php, a problem jump out... "The used table type doesn't support FULLTEXT indexes".This is the first time I meet this kind MySQL problem.I searched on Google and got the answer.
"This message appears when the database server is configured to use another table type than MyISAM."
original code -
CREATE TABLE forum_posts (
id int(11) NOT NULL auto_increment,
topic_id int(11) NOT NULL default '0',
forum_id int(11) NOT NULL default '0',
author_id int(11) NOT NULL default '0',
update_id int(11) NOT NULL default '0',
date_posted datetime NOT NULL default '0000-00-00 00:00:00',
date_updated datetime NOT NULL default '0000-00-00 00:00:00',
subject varchar(255) NOT NULL default '',
body mediumtext NOT NULL,
PRIMARY KEY (id),
KEY IdxArticle (forum_id,topic_id,author_id,date_posted),
FULLTEXT KEY IdxText (subject,body)
) TYPE=MyISAM //add the red code to correct the mistake.
If you meet the same problem, hope the article can help you.
Monday, February 05, 2007
Something about PHP File Upload
Today, I learned something about PHP File Upload and found a good place to study.
http://www.w3schools.com/
http://www.w3schools.com/
Saturday, February 03, 2007
Some suggestion to learn PHP and truely understand it
Today I read 2 artcles, found them were very useful for those who are learning and using PHP.Please do not satisfy with what you have learned.Always keep on learning...
1. How to Learn PHP (and Understand It)
I don’t think there’s a day that goes by that I don’t see someone just coming into the world of PHP, eyes bright with promise and hope, ready to tackle just about anything that comes their way. Of course, reality sinks in and, unless they’re already pretty well versed with programming and the thought processes that go on behind it, they might take one look at PHP and run screaming...
2. Just PHP will give you nothing… unless you upgrade yourself
I have been working with PHP for more than 3yrs (I believe still I am beginner in this category) - I was present in several interview board. Which things disappointed me most is the “lack of eagerness” to learn what comes new. Sometime developers thinks that learning Only PHP will help them to get lucrative jobs...
I am a beginner to PHP...So I think I have to start some small projects and do some freelance jobs.Only in this way can enhance my programming level.Practice makes perfect, the more you practice the better you get.Always keep on learning and practising...
1. How to Learn PHP (and Understand It)
I don’t think there’s a day that goes by that I don’t see someone just coming into the world of PHP, eyes bright with promise and hope, ready to tackle just about anything that comes their way. Of course, reality sinks in and, unless they’re already pretty well versed with programming and the thought processes that go on behind it, they might take one look at PHP and run screaming...
2. Just PHP will give you nothing… unless you upgrade yourself
I have been working with PHP for more than 3yrs (I believe still I am beginner in this category) - I was present in several interview board. Which things disappointed me most is the “lack of eagerness” to learn what comes new. Sometime developers thinks that learning Only PHP will help them to get lucrative jobs...
I am a beginner to PHP...So I think I have to start some small projects and do some freelance jobs.Only in this way can enhance my programming level.Practice makes perfect, the more you practice the better you get.Always keep on learning and practising...
Friday, February 02, 2007
My first Post on my blog...
I got this blog on Oct 6th, 2006.Just came and have a look for google's new product.I found it was funny and post a test page.But at this time,I really decide to write something.
For my first post.I want to introduce some websites I often use.May be useful for you too.
1. www.getafreelancer.com - A very useful site to find a PHP freelance job.Also other programming language jobs..."Become a freelance programmer, web designer, copywriter or translator and let us help you find customers from all over the world! It's free to sign up. Join us and start making money Today!"
2. www.statcounter.com - A free yet reliable invisible web tracker, highly configurable hit counter and real-time detailed web stats. Insert a simple piece of their code on your web page and you will be able to analyse and monitor all the visitors to your website in real-time! Free to use 100 logs,need pay for more...But I think it's enough for personal use.
3. www.fromshawn.com - Some free SEO sofeware..."Who Else Is Sick Of The SEO Hype??? Want Some FREE SEO Tools That Are Better Than The Paid Ones??? Here Ya Go..."
Hope all of these information are useful for you...
For my first post.I want to introduce some websites I often use.May be useful for you too.
1. www.getafreelancer.com - A very useful site to find a PHP freelance job.Also other programming language jobs..."Become a freelance programmer, web designer, copywriter or translator and let us help you find customers from all over the world! It's free to sign up. Join us and start making money Today!"
2. www.statcounter.com - A free yet reliable invisible web tracker, highly configurable hit counter and real-time detailed web stats. Insert a simple piece of their code on your web page and you will be able to analyse and monitor all the visitors to your website in real-time! Free to use 100 logs,need pay for more...But I think it's enough for personal use.
3. www.fromshawn.com - Some free SEO sofeware..."Who Else Is Sick Of The SEO Hype??? Want Some FREE SEO Tools That Are Better Than The Paid Ones??? Here Ya Go..."
Hope all of these information are useful for you...
Subscribe to:
Posts (Atom)