tag:blogger.com,1999:blog-7623063165553655962024-03-14T09:51:55.149+07:00thiet ke web,thiet ke giao dien,thiet ke phan mem,seo len googlehoc thiet ke web,thiet ke web da nghanhUnknownnoreply@blogger.comBlogger60125tag:blogger.com,1999:blog-762306316555365596.post-52710709795517146652012-08-12T12:37:00.002+07:002012-08-12T12:40:37.488+07:00Loa AF04Loa Nghe Nhac AF04<br />
Bảo hành 12 tháng<br />
Giá: 146 VNĐ<br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/--vHC1hV6ynU/UCdAvFNUgtI/AAAAAAAAADo/Yd3rUK5jwAs/s1600/19.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/--vHC1hV6ynU/UCdAvFNUgtI/AAAAAAAAADo/Yd3rUK5jwAs/s1600/19.PNG" /></a></div><div class="separator" style="clear: both; text-align: center;"><br />
</div><div class="separator" style="clear: both; text-align: left;"></div><br />
>Chức năng chỉ cần cắm USB hoặc thẻ nhớ vào là có thể nghe nhạc.<br />
Công Dụng:Loa cho điện thoại+láp tóp+Máy PC<br />
Âm thanh:Trung thực,Lớn,Không Rè,Bass cao<br />
Thời gian đàm thoại:Từ 4 đến 5 giờ tùy Volume<br />
Phụ kiện:cáp kết nối âm, cục sạc...<br />
Liên Hệ: A Tuân:0166 2428 200<br />
Hoặc A Quang:0908 113 095<br />
<br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-45982989600284979502012-06-16T23:27:00.000+07:002012-06-16T23:27:01.238+07:00Google Sitemap<h1 class="entry-title">
Google Sitemap Generator 2.3</h1>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-6r2jbYZdbGY/T7k4A96OfwI/AAAAAAAAADM/KiQ0mBI7ShI/s1600/v1.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="112" src="http://2.bp.blogspot.com/-6r2jbYZdbGY/T7k4A96OfwI/AAAAAAAAADM/KiQ0mBI7ShI/s200/v1.png" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">thietkewebsite</td><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>
<div class="entry-info">
<span class="entry-cat"><strong><a href="http://www.seohay.org/">SEO Hay</a>: </strong><a href="http://www.thietkewebso.com/">SEO cho website</a></span>
</div>
<div style="float: left; margin: 3px; padding-left: 0px; padding: 7px;">
</div>
<strong>Google Sitemap Generator</strong><br />
Plugin này sẽ tạo ra một XML-sitemap cho blog tương thích với Google
sitemap. Bạn có thể submit sitemap này lên Google Webmaster Tool gúp
Google dễ dàng biết được bản đồ blog của bạn,<span style="color: red;"> hay nói cách cho biết
blog của bạn có những trang nào để Google dễ dàng đáng chỉ mục hơn.</span><br />
<a name='more'></a><br />
Nó có thể tạo ra sitemap cho tất cả các trang hay chỉ một số trang
cho blog, tùy theo ý thích của bạn. Ngay sau khi bạn chỉnh sửa một bài
viết hay viết một bài viết mới, sitemap của bạn ngay lập tức được cập
nhật và nó tự động thông báo cho tất cả các Search Engine lớn như
Ask.com, Google, MSN Search và Yahoo về sự thay đổi này.<br />
<strong>Download</strong><br />
Sau khi download về máy tính, hãy giải nén plugin để chuẩn bị upload lên blog.<br />
<strong>Cài đặt</strong><br />
1. Upload toàn bộ lên thư mục wp-content/plugins trên blog<br />
2. Hãy cấu hình để thư mục blog của bạn có thể viết lên được
(writable) hoặc tạo hai file có tên là sitemap.xml và sitemap.xml.gz và
chỉnh cho chúng có thể viết lên được bằng CHMOD. Trong hầu hết các
trường hợp, thư mục blog của bạn đã để chế độ có thể viết lên được
(writable) nên bạn không cần phải làm gì.<br />
3. Phải chắn chắn hai điều là: Thư mục blog của bạn có thể writable
hoặc đã có hai file có tên sitemap.xml và sitemap.xml.gz có thể
writable.<br />
4. Active plugin này trong phần Plugins<br />
5. Chỉnh sửa lại hay viết một bài mới hoặc click vào Rebuild Sitemap
ở Giao diện quản trị Sitemap có tên là XML Sitemap nằm ở dưới mục
Options.<br />
Như thế là đã xong, plugin này sẽ tự động tạo ra sitemap và sẽ thông báo sitemap của bạn cho các Search Engine.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-43547350189087645812012-06-16T23:20:00.000+07:002012-06-16T23:20:34.680+07:00Sitemap là gì<h1 class="entry-title">
</h1>
<div style="float: left; margin: 3px; padding-left: 0px; padding: 7px;">
</div>
<div style="background-color: red;">
Site map (sơ đồ của một website) <strong>là</strong> một danh lục
liệt kê tất cả các mục thông tin trên trang web của bạn cùng sự mô tả
ngắn gọn cho các mục thông tin đó.</div>
<a name='more'></a> Site map nên được sử dụng dễ dàng
trong việc thực hiện tìm kiếm nhanh để tìm ra thông tin cần thiết cũng
như trong việc di chuyển thông qua các đường link trên website của bạn.
<strong>Sitemap</strong> nên <strong>là</strong> một sơ đồ hoàn hảo nhất của website.<br />
<strong>Site map <strong>là</strong> sự cần thiết cho trang web của bạn</strong>
để đạt được một vị trí cao trong các hệ thống tìm kiếm, bởi vì các hệ
thống tìm kiếm đánh giá rất cao cho các trang web có một sơ đồ điều
hướng truy cập website.<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<strong>Một site map nên được bao gồm như sau:</strong><br />
Một chú thích ngắn về website, sử dụng các từ khoá cơ bản trong các
đường link text dẫn đến các trang chính của bảng điều hướng chuẩn trên
site của bạn (bảng này cũng có nhiều từ khóa) nơi có mọi đường link
khác kết nối tới tất cả các trang trên website.<br />
Một site map tốt nên dẫn tới được mọi vị trí trên website. Bằng cách
này bạn sẽ có được sự ưu tiên lớn trong khi tìm kiếm hệ thống.<br />
<strong>Lời khuyên quan trọng khi tạo các site map</strong><br />
- Một <strong>sitemap</strong> nên tương ứng với thiết kế của trang
web. Hãy xuất phát từ khái niệm thông thường, như được đề cập trong
bất cứ tài liệu tương tự khác nào, một site map không mang lại cho
trang web của bạn sự đánh giá đầy đủ về mức độ thu hút mà thậm chí
ngược lại còn có thể làm những người dùng hoảng sợ.<br />
- Không nên sử dụng những yếu tố đồ hoạ trong khi tạo một <strong>sitemap</strong>.
Thời gian gần đây, hầu hết người sử dụng lướt Web vào những trang
trên Internet ở chế độ ngăn chặn đồ họa. Vì lý do này nên sự xuất hiện
của đồ hoạ như <strong>là</strong> những yếu tố điều hướng truy cập trên <strong>sitemap</strong> của bạn sẽ không được xem <strong>là</strong> có ích lắm, vì chúng sẽ không hoạt động cho tất cả người dùng, và sơ đồ sẽ chỉ <strong>là</strong> sự thể hiện chưa được thành công cho sáng tạo của bạn. Bởi thế, lý tưởng <strong>là</strong> một site map nên nhìn giống nhau trong tất cả các trình duyệt khi mọi người truy cập web.<br />
- Cấu trúc của sơ đồ nên có tương quan với chính hệ thống có tính
phân cấp của web. Vì cấu trúc của một sơ đồ trang web nên cần được sử
dụng các tiêu đề và danh sách. Không nên sử dụng các bảng cho cấu trúc
sơ đồ vì nó khiến cho quy trình này nhiều khó khăn hơn.<br />
- Nên đặt đường liên kết tới sơ đồ website trên trang chính hoặc
trang đầu của trang web hoặc theo một cách nào đó tương tự để người
dùng có thể sử dụng được dễ dàng khi cần thiết. Sao cho người sử dụng
sẽ không ngừng một giây nào để nghĩ về điều họ nên làm <strong>gì</strong>, khi họ không biết làm <strong>gì</strong> hơn nữa sau khi truy cập vào website của bạnUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-34457192537438595012012-06-16T23:12:00.004+07:002012-06-16T23:12:29.627+07:00Cách tạo sitemap cho website<h1 class="entry-title" style="background-color: yellow;">
Những định nghĩa cũng như <strong>cách</strong> làm <strong>sitemap</strong> <strong>cho</strong> yahoo, <strong>sitemap</strong> của google <strong>cho</strong> wordpress đã được giới thiệu.<a name='more'></a> Bài viết này sẽ chỉ <strong>cho</strong> bạn <strong>cách</strong> làm <strong>sitemap</strong> <strong>cho</strong> một <strong>website</strong> bất kỳ không phải là mã nguồn mở như joomla, drupal, wordpress (những mã nguồn này đều có plugin để tự cập nhật <strong>sitemap</strong>).</h1>
<div style="background-color: yellow; float: left; margin: 3px; padding: 7px 7px 7px 0px;">
</div>
<div style="background-color: yellow;">
<strong>Hướng dẫn làm <strong>sitemap</strong></strong></div>
<div style="background-color: yellow;">
Chuẩn bị:</div>
<ul style="background-color: yellow;">
<li><strong>Website</strong> (tất nhiên rồi)</li>
<li>Notepad ++ , <a href="http://notepad-plus.sourceforge.net/uk/site.htm" rel="nofollow">down ở đây</a></li>
<li>Internet (mạng mạnh 1 chút <strong>cho</strong> các <strong>website</strong> lơn gần 500 hoặc hơn 500 trang)</li>
</ul>
<div style="background-color: yellow;">
Có rất nhiều phần mềm hỗ trợ làm <strong>sitemap</strong> như Gsitemap, nhưng bài viết này sẽ hướng dẫn <strong>cách</strong> làm <strong>sitemap</strong> bằng những dịch vụ free trên mạng internet.</div>
<div style="background-color: yellow;">
<strong>Bước 1</strong>: Vào web <strong><strong>tạo</strong> site map </strong> (web này là uy tín nhất về việc làm <strong>sitemap</strong>), khuyến kích sử dụng trình duyệt web firefox.</div>
<div style="background-color: yellow;">
- Điền domain <strong>website</strong> của bạn vào: Starting Url (chú ý redirect nhé)<br />
- Chọn thông số Frequensy<br />
- Tại Priority: bạn có 2 lựa chọn là tự động thiết lập hoặc thiết lập bằng tay. (auto <strong>cho</strong> nó nhanh)<br />
Click: Start<br />
Chờ <strong>cho</strong> nó chạy song, web đơn gian thì nhanh, mà phức tạp thì hơi lâu đây.<br />
Khi chạy song bạn sẻ nhận được 1 list các file <strong>sitemap</strong>. dạng yymmddss-seoviet-<strong>sitemap</strong>.xml</div>
<div style="background-color: yellow;">
<strong>Bước 2</strong>: Down 4 file ở trên về máy.<br />
- Sử dụng notepad ++ mở file <strong>sitemap</strong>.xml đẻ set thông số Priority <strong>cho</strong> các url theo ý bạn.<br />
Lưu ý phần này: thông số Priority quy định sự quan trong của các url đối với <strong>website</strong> của bạn, nếu Url nào quan trọng nên <strong>cho</strong> nó cao điểm hơn, cao nhất là 1.0 và thấp nhất 0.10</div>
<div style="background-color: yellow;">
<strong>Bước 3</strong>: Cuối cùng là Upload lên root web và verify <strong>sitemap</strong>.</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-79878773131948350092012-06-16T23:07:00.000+07:002012-06-16T23:07:05.645+07:00Lợi ích của việc dựng Sơ đồ website Sitemap<h1 class="entry-title">
</h1>
<div style="float: left; margin: 3px; padding-left: 0px; padding: 7px;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-lS011DlJQPo/T7PU09qRonI/AAAAAAAAACU/0F1segBklSo/s1600/images.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="148" src="http://1.bp.blogspot.com/-lS011DlJQPo/T7PU09qRonI/AAAAAAAAACU/0F1segBklSo/s320/images.jpg" width="320" /></a></div>
<strong>Sơ</strong> <strong>đồ</strong> trang web giúp công cụ tìm kiếm phát hiện ra nội dung trên trang web <strong>của</strong> bạn. Hãy suy nghĩ <strong>sơ</strong> <strong>đồ</strong> <strong>của</strong> một trang web như cách <strong>của</strong> bạn vào gõ cửa một công cụ tìm kiếm để cho họ biết là nội dung mới hoặc cập nhật trên trang web <strong>của</strong> bạn<br />
<a name='more'></a>.<br />
<i>Thêm một <strong>sitemap</strong> cho trang web <strong>của</strong> bạn là một trong những chiến lược cơ bản nhất để có được nội dung thu thập dữ liệu và lập chỉ mục <strong>của</strong> công cụ tìm kiếm. Vấn đề là, hầu hết mọi người chỉ dính vào hai loại <strong>sơ</strong> <strong>đồ</strong> trang web phổ biến nhất HTML và XML. Trên <strong>sơ</strong> <strong>đồ</strong> trang web có chứa một danh sách các URL khác nhau trên trang web <strong>của</strong> họ.</i><br />
<i><strong>Sơ</strong> <strong>đồ</strong> trang web biết đến trong nhiều dạng khác nhau và các định dạng và có thể rất hữu <strong>ích</strong>,
nhận được tất cả mọi thứ từ nội dung phong phú bao gồm phương tiện
truyền thông trong tìm kiếm phổ biến để nhận được tin tức <strong>của</strong> bạn hoặc cập nhật thông cáo báo chí bao gồm trên Google hay Yahoo News.</i><br />
<i>Chúng ta hãy xem xét lại trong 6 loại <strong>sơ</strong> <strong>đồ</strong> sau:</i><br />
<h3>
<i><strong>Sơ</strong> <strong>đồ</strong> trang web HTML</i></h3>
<i>HTML là các bản <strong>đồ</strong> trang web, phổ biến nhất thường là một trang web có một chỉ số <strong>của</strong> tất cả các trang khác trên trang web <strong>của</strong> bạn.Công cụ tìm kiếm theo những liên kết này giống như họ sẽ từ bất kỳ trang web khác trên trang web <strong>của</strong> bạn.</i><br />
<h3>
<i><strong>Sơ</strong> <strong>đồ</strong> trang web XML</i></h3>
<i>XML <strong>Sơ</strong> <strong>đồ</strong> trang web, hoặc <strong>sơ</strong> <strong>đồ</strong> trang web máy, chứa thông tin thêm về các URL trang web <strong>của</strong>
bạn bao gồm cách thường xuyên họ được cập nhật và làm thế nào mỗi
URL sẽ được ưu tiên so với các trang khác trên trang web. Định dạng này
<strong>sitemap</strong> được chấp nhận bởi công cụ tìm kiếm lớn các nền tảng công cụ quản trị trang web.</i><br />
<h3>
<i>Hình ảnh <strong>Sơ</strong> <strong>đồ</strong> trang web</i></h3>
<i>Bạn có muốn được bao gồm trong tìm kiếm hình ảnh hoặc tìm kiếm phổ
quát có tính năng hình ảnh? Một trong những cách tốt nhất để làm như vậy
là bao gồm một bản <strong>đồ</strong> hình ảnh. Hình ảnh <strong>sơ</strong> <strong>đồ</strong> trang web cũng có thể bao gồm vị trí địa lý <strong>của</strong> hình ảnh, mà có thể giúp nó có được lập chỉ mục trên trái đất <strong>của</strong> Google hoặc trên các bản <strong>đồ</strong> <strong>của</strong> Google.</i><br />
<i>Trong khi có nhiều máy phát điện miễn phí có sẵn trực tuyến, bạn có thể kết hợp ba <strong>sơ</strong> <strong>đồ</strong> trang web ở trên vào <strong>sơ</strong> <strong>đồ</strong> trang web chính là một cách sử dụng một công cụ chi phí thấp như XML-Sitemaps.com <strong>Sơ</strong> <strong>đồ</strong> trang web không giới hạn.</i><br />
<h3>
<i><strong>Sơ</strong> <strong>đồ</strong> trang web Video</i></h3>
<i>Bạn có nội dung video mà bạn thích máy chủ trên trang web <strong>của</strong> bạn hơn là trên các trang web bên thứ ba như YouTube? Nếu có, sau đó là một <strong>sơ</strong> <strong>đồ</strong>
trang web video là rất quan trọng để nhận được những đoạn phim này
được công nhận và thậm chí cả bao gồm trong kết quả tìm kiếm phổ
quát. Phần mở rộng <strong>của</strong> Google video <strong>của</strong> giao thức <strong>Sơ</strong> <strong>đồ</strong>
trang web cho phép bạn để cung cấp cho Google thông tin mô tả,
chẳng hạn như video là một tiêu đề, mô tả, thời gian, mà làm cho nó
dễ dàng hơn cho người dùng tìm thấy một đoạn cụ thể <strong>của</strong> nội dung.Google có thể sử dụng văn bản có sẵn trên trang video <strong>của</strong> bạn hơn là các văn bản bạn cung cấp trong nội dung <strong>của</strong> video <strong>Sơ</strong> <strong>đồ</strong>
trang web, nếu có khác biệt. Google có thể thu thập thông tin
Flash SWF đối tượng và các loại file video sau liệu: ra. Mpg.,.,
Mpeg,.. Mp4 ram,., Mov,.. Wmv rm,., Asf,.. Avi flv,. Tất cả các file
phải được truy cập qua web. Một công cụ tiện dụng là Video <strong>Sơ</strong> <strong>đồ</strong> <strong>website</strong> Pro cho cả Windows và Mac.</i><br />
<h3>
<i>Tin tức <strong>Sơ</strong> <strong>đồ</strong> trang web</i></h3>
<i>Nếu bạn xuất bản bản tin địa phương hoặc chạy một trang web nội
dung cung cấp thông tin đáng đưa tin, nhận được đăng trên tập hợp tin
tức lớn như Google và Yahoo News có thể lái xe số tiền rất lớn <strong>của</strong> lưu lượng truy cập vào trang web <strong>của</strong> bạn. Nếu bạn chạy trang web <strong>của</strong> bạn trên một nền tảng phổ biến như WordPress, có plug-in sẵn để thực hiện tạo ra một <strong>sơ</strong> <strong>đồ</strong>
trang web tin tức dễ dàng. Plug-in có sẵn cho hệ thống quản lý nội
dung khác, nhưng bạn nên chắc chắn rằng họ thực hiện theo hướng dẫn <strong>của</strong> <strong>sơ</strong> <strong>đồ</strong> trang web tin tức Google.</i><br />
<h3>
<i>Geo-<strong>Sơ</strong> <strong>đồ</strong> trang web (KML)</i></h3>
<i>Geo-<strong>sơ</strong> <strong>đồ</strong> trang web rất hữu <strong>ích</strong> nếu bạn hoạt động hoặc quản lý và kinh doanh gạch vữa, hoặc có một chuỗi các quyền thương mại. Bao gồm một <strong>sơ</strong> <strong>đồ</strong> trang web cho phép vị trí địa lý <strong>của</strong>
bạn được tìm thấy trên Google Earth và cũng có một tác động tích cực
trên Google xếp hạng các điểm khi họ thêm vào “nội dung người sử
dụng” các yếu tố xếp hạng. Để tạo ra một bản <strong>đồ</strong> bạn có thể sử dụng Geo sự lên bản <strong>đồ</strong> và máy phát điện KML (beta).</i>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-31030648112628319212012-06-16T23:03:00.003+07:002012-06-16T23:03:49.002+07:00Nhược điểm của SEO<div class="pane" style="display: block;">
<span style="font-size: x-small;">Joomla một hệ thống CMS mã nguồn mở
"hoành cháng" nhất hiện nay, các template và extension dành cho open
source này nhiều vô kể, đặc biệt là trong lĩnh vực làm SEO cho website
sử dụng mã nguồn này. </span><br />
<a name='more'></a><br />
<span style="font-size: x-small;">Nhưng "lắm thầy lại nhiều ma" chúng
ta có thể gặp nhiều khó khăn trong việc lựa chọn các sử dụng extension
nào cho hợp lý trong trường hợp làm sef url cho website. Trong bài viết
này chúng ta sẽ cũng so sánh hiệu quả của các extension này, hy vọng
sẽ giúp được nhiều cho các bạn có ý định tìm và sử dụng các phần mở
rộng hỗ trợ việc quảng bá website của mình.</span><br />
<div style="text-align: center;">
<span style="font-size: x-small;"><a href="http://www.thietkewebso.com/" target="_blank"><img alt="webgiare123.com" border="0" height="330" src="http://webgiare123.com/images/stories/thumbnails/images-stories-ImageBaiviet-joomla-1.5-seo-extensions-483x330.png" width="483" /></a></span></div>
<span style="font-size: x-small;">Bảng phân tích trên dựa trên các yếu tố thiên về tối ưu hóa cho website, đóng góp hầu hết trong việc làm onpage SEO cho joomla</span><br />
<ul>
<li><span style="font-size: x-small;">SEF URL: Tạo url thân thiện với máy tìm kiếm, bằng cách thay các đoạn code bằng tiêu đề của bài viết cụ thể.</span></li>
<li><span style="font-size: x-small;">Meta data: Quản lý, sắp xếp meta tag cho các trang cụ thể</span></li>
<li><span style="font-size: x-small;">No follow: chứng năng gáng thẻ nofollow cho các out-link</span></li>
<li><span style="font-size: x-small;">404 Pages: Trang thông báo link gãy</span></li>
<li><span style="font-size: x-small;">Cross-Linking: Hỗ trợ nội liên kết</span></li>
<li><span style="font-size: x-small;">H1 tag: Hỗ trợ heading tag</span></li>
<li><span style="font-size: x-small;">Alt tag: Hỗ trợ thẻ alt cho hình ảnh</span></li>
</ul>
<h3>
<span style="font-size: x-small;">Tổng kết của SEO Vietnam:</span></h3>
<span style="font-size: x-small;">Qua bảng đánh giá trên phần nào chúng
ta cũng nhận ra được extension nào là tốt nhất trong thời điẻm hiện
tại. Hiện tại Advanced SEF đang được đánh giá cao nhất, sau đó đến
sh404sef và Artio SEF. Với kinh nghiệm trong Joomla của mình, thì mình
khuyên các bạn nên sử dụng sh404sef hoặc là Artio SEF vì tính phổ biến
của 2 extension này cộng thêm những plugin viết thêm cho chúng rất
nhiều. Các bạn có thể dễ dàng tìm thấy trên mạng.</span></div>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-762306316555365596.post-39341764674230006362012-06-16T23:01:00.001+07:002012-06-16T23:01:23.913+07:00Ưu điểm của SEO<div class="pane" style="display: block;">
<strong>Quảng cáo SEO</strong> <strong>website</strong> không giới hạn về thời gian xuất hiện cũng như số lượng click hay hiển thị như các <strong>quảng cáo</strong> CPC, CPM khác<br />
<a name='more'></a><br />
Theo các nghiện cứu trên thế giới và ở Việt Nam đã chỉ ra rằng 88% người dùng click vào kết quả tự nhiên, 12% click vào <strong>quảng cáo</strong> tài trợ khi tìm kiếm. Như vậy cùng 1 vị trí quảng cáo thì chi phí cho <strong>quảng cáo SEO website</strong> rẻ hơn so với <strong>quảng cáo</strong> tài trợ<br />
Nếu thương hiệu của bạn xuất hiện trên các vị trí Organic tự nhiên
thì đẳng cấp và chính bản thân website của bạn tốt hơn nhiều lần vì phải
thật tốt bạn mới được Google đánh giá cao như vậy trên Organic results<br />
Vị trí của từ khóa trong <strong>quảng cáo website </strong>được duy
trì ổn định cao do đó giúp cho chủ doanh nghiệp dự trù được chi phí lâu
dài, so với các quảng cáo khác giá sẽ thay đổi theo vị trí xuất hiện,
số lần xuất hiện hoặc chia sẻ vị trí<br />
Quảng cáo SEO website còn giúp cho doanh nghiệp phát triển website
với nội dung tốt. Các doanh nghiệp đôi khi không quá chú ý tới việc tối
ưu nội dung website cho người dùng.</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-69852949411122560032012-06-16T22:55:00.001+07:002012-06-16T22:55:21.920+07:00Dịch vụ SEO -( Search Engine Optimization)<table border="0" cellpadding="0" id="table328"><tbody>
<tr><td height="18" style="color: black; font-family: Verdana,sans-serif;" valign="top"><span lang="en-us" style="font-weight: 700;"></span></td>
</tr>
<tr>
<td background="images/kengang.gif" style="color: black; font-family: Verdana,sans-serif;">
<img border="0" height="3" src="http://www.vietnamtradefair.com/dv/images/kengang.gif" width="4" /></td>
</tr>
<tr>
<td style="color: black; font-family: Verdana,sans-serif;"> </td>
</tr>
<tr>
<td>
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt; font-weight: 700;">
<span style="color: red;">Tối ưu hóa Website cho máy tìm kiếm</span></span></div>
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt;"><span style="color: red;">Search Engine
Optimization (SEO) hay còn gọi là tối ưu hóa Website cho
máy tìm kiếm là chiến dịch quảng bá trực tuyến hiệu quả
nhất đối với các khoản đầu tư vào bất cứ kỹ thuật quảng
cáo trực tuyến nào khác.</span></span></div>
<a name='more'></a><span style="font-family: Verdana; font-size: 8pt;"> Khách hàng đến với Website của
bạn từ các máy tìm kiếm rất tiềm năng vì họ quan tâm
trực tiếp đến sản phẩm và dịch vụ của công ty. Bởi vậy,
tối ưu hóa Website cho công cụ tìm kiếm đảm bảo cho công
việc kinh doanh của bạn có được tỷ số chuyến đổi rất cao
so với các phương thức marketing trực tuyến nào khác.</span><br />
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt;">Tối ưu hóa
Website cho máy<span lang="en-us"> chủ</span> tìm kiếm
đảm bảo các lợi ích bao gồm:</span></div>
<ul style="background-color: yellow;">
<li>
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt;">Mang lại
khách hàng tiềm năng, quan tâm trực tiếp đến sản
phẩm, dịch vụ <span lang="en-us">trên website đang
</span>kinh doanh của công ty<span lang="en-us">.</span>
</span></div>
</li>
<li>
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt;">Quảng bá
thương hiệu của công ty cho khách hàng tìm kiếm.
Ngoài ra việc xếp hạng cao trên máy tìm kiếm, thương
hiệu sẽ được người dùng nhìn nhận với độ tin cậy cao
hơn<span lang="en-us"> rất nhiều.</span> </span>
</div>
</li>
<li>
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt;">Đảm bảo tỷ
lệ <span lang="en-us">giao dịch thành công</span>
cao<span lang="en-us">, cả về</span> lượng khách
viếng thăm<span lang="en-us"> website</span> và
<span lang="en-us">c</span>ác <span lang="en-us">
giao dịch</span> thương mại thực hiện trên trang<span lang="en-us">
web</span> của công ty, cao hơn bất kể hình thức
thương mại<span lang="en-us">, truyền thông hay</span>
quảng cáo trực tuyến nào khác<span lang="en-us">.</span>
</span></div>
</li>
<li>
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt;">Kết quả
tối ưu hóa Website sẽ được giữ vững trong một thời
gian dài, ít nhất là trong một vài năm. </span></div>
</li>
</ul>
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt;">Chiến dịch SEO
<a href="http://www.thietkewebso.com/" target="_blank" title="quang ba website"> quảng bá Website</a> của công ty sẽ kéo theo việc tối ưu
mã nguồn HTML tuân thủ các chỉ dẫn của Google cho
Webmaster về thiết kế kỹ thuật, chất lượng. Dịch vụ tối
ưu hóa Website của ECO sẽ ứng dụng các chuẩn, khuyến cáo
hay công cụ của máy tìm kiếm (vị dụ Meta Tags hay
Sitemap XML, Sitemaps Video, Pings). Bên cạnh các yếu tố
kỹ thuật, ECO sẽ tiến hành song song việc trình bày nội
dung.</span></div>
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt;">Trọn gói quảng<span lang="en-us">
bá</span> Website của công ty ECO bao gồm cả phân tích
Website và nghiên cứu từ khóa. Hơn nữa, ECO sẽ tiến hành
tối ưu mã nguồn HTML của quý công ty và báo cáo theo dõi
tính hiệu quả hàng tháng.</span></div>
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt; font-weight: 700;">
Phân tích từ khóa</span></div>
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt;">Việc xác định
<span lang="en-us">đ</span>úng từ khóa hợp lý sẽ góp
phần thành công cho chiến dịch quảng bá trên
<span lang="en-us">cỗ </span>máy <span lang="en-us">chủ
</span>tìm kiếm. Dù cho bạn tham gia vào chương trình
trả ti<span lang="en-us">ề</span>n cho lượt truy cập,
theo đuổi chiến dịch SEO - tối ưu hóa Website cho máy
tìm kiếm đơn lẻ hay theo đuổi trọn gói chương trình tiếp
thị máy tìm kiếm thì việc xác định danh sách từ khóa
liên quan tới sản phẩm và dịch vụ của công ty luôn là
vấn đề thiết yếu.</span></div>
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt;">Công ty ECO
khuyến khích việc sử dụng dịch vụ phân tích từ khóa như
là một phần trong nỗ lực quảng bá tiếp thị máy tìm kiếm.
ECO sẽ hỗ trợ công ty các chiến thuật từ khóa và từ khóa
tùy biến cho từng sản phẩm. Hãy liên lạc với chúng tôi.</span></div>
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt; font-weight: 700;">
Chiến dịch xây dựng liên kết</span></div>
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt;">Hệ thống liên
kết, một trong những tiêu chí xếp hạng Website của máy
tìm kiếm, đánh dấu sự thay đổi quan trọng nhất trong vài
năm qua trong lĩnh vực tối ưu hóa Website cho công cụ
tìm kiếm. Tất cả các máy tìm kiếm chính (Google, Yahoo,
M<span lang="en-us">SN</span>) đều xem xét chất lượng
của hệ thống liên kết trước khi xếp hạng trang.</span></div>
<div align="justify">
<span style="font-family: Verdana; font-size: 8pt;">Các phương
pháp tự động kết hợp với việc tiếp cận được tùy biến một
cách thân thiện cho phép ECO đảm bảo mang lại các liên
kết chất lượng cho khách hàng. Công ty ECO không sử dụng
phương pháp spam email hay tham gia “trang trại liên
kết” có thể gây ra phi<span lang="en-us">ề</span>n toái
với các máy tìm kiếm. Phương pháp của ECO tiến hành
trong một thời gian ngắn và trung bình nhưng mang lại
hiệu quả tức thì.</span></div>
</td></tr>
</tbody></table>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-72634632336363246892012-06-16T22:51:00.000+07:002012-06-16T22:51:05.939+07:00Bảo trì website<div align="justify" style="line-height: 150%;">
<span style="font-family: Verdana; font-size: 8pt;">Dùng tạo các trang web động, với các phần mềm là các modul người
quản lý website không chỉ có thể thay đổi các nội dung trên website
của mình mà còn tạo được mối liên hệ chặt chẽ vối khách hàng thông
qua các diễn đàn hoặc tư vấn.</span></div>
<a name='more'></a><span style="font-family: Verdana; font-size: 8pt;"><br />
<span style="color: #ce0000;"><b>A. Modul Tin mới- (New)</b></span></span><span style="font-family: Verdana; font-size: 8pt;"><br />
<b>Mục đích<br />
</b>Giới thiệu các tin túc mới nhất trong hoạt động kinh doanh cũng
như các thông tin khác về công ty.<br />
Các thông tin này làm người xem (khách hàng) sẽ hiểu rõ hơn về đối
tác mà họ dang hoặc sắp hợp tác.<br />
Phần này sẽ được thiết kế như một bản tin gồm nhiều tin mới bao gồm:</span><br />
<span style="font-family: Verdana; font-size: 8pt;">
</span>
<span style="font-family: Times New Roman; font-size: 8pt;">
<ul>
<li>
<div align="justify" style="line-height: 150%;">
Tiêu đề của bài viết
nêu lên chủ đề chính của bài viết.</div>
</li>
<li>
<div align="justify" style="line-height: 150%;">
Thông tin ngắn tóm
tắt nội dung bài viết.</div>
</li>
<li>
<div align="justify" style="line-height: 150%;">
Một ảnh có kèm theo
nội dung minh hoạ cho ảnh. Khi kích chuột vào ảnh hoặc Tiêu đề của
bài viết thì sẽ xem được nội dung chi tiết</div>
</li>
</ul>
<div align="justify" style="line-height: 150%;">
Trong cửa sổ giới thiệu
nội dung chi tiết, ảnh của thông tin sẽ được thu nhỏ (thumnail). Khi
lích chuột vào ảnh hoặc dòng giải thích cho thông tin , sẽ mở ra một
cửa sổ mới (popup)để hiển thị ảnh ở kích thước đầy đủ cùng nội dung
thông tin.</div>
</span><span style="font-family: Times New Roman; font-size: medium;">
<span style="color: #ce0000; font-family: Verdana; font-size: 8pt; font-weight: 700;">
<div align="justify" style="line-height: 150%;">
B. Modul sản phẩm
(Produce Cataloge)</div>
</span>
<span style="font-family: Verdana; font-size: 8pt;">
<div align="justify" style="line-height: 150%;">
Nhằm mục đích giới
thiệu về các ấn phẩm của Công ty, làm cho khách hàng thấy trước được
sản phẩm họ sẽ dùng. Chương trình Cataloge sẽ trợ giúp người quản
trị website tổ chức phân chia sản phẩm theo nhóm. Các sản phẩm trong
từng nhóm sẽ làm nổi bật hình ảnh các sản phẩm cùng các thông tin
số, tính năng của sản phẩm. Do đó khách hàng sẽ dễ dàng hơn trong
việc lựa chọn sản phẩm.</div>
<div align="justify" style="line-height: 150%;">
Phần náy sẽ được tổ
chức như một Cataloge. Các sản phẩm sẽ được chia nhóm theo các công
ty thành viên. Mỗi công ty có một nhóm các sản phẩm tiêu biểu riêng
của mình và bản thân danh mục các sản phẩm ó thể chia nhóm nhỏ hơn.
Thông tin về mỗi sản phẩm tiêu biểu gồm :</div>
<ul>
<li>
<div align="justify" style="line-height: 150%;">
Mã sản phẩm.</div>
</li>
<li>
<div align="justify" style="line-height: 150%;">
Tên sản phẩm</div>
</li>
<li>
<div align="justify" style="line-height: 150%;">
ảnh của sản phẩm.</div>
</li>
<li>
<div align="justify" style="line-height: 150%;">
Kích thước của snả
phẩm.</div>
</li>
<li>
<div align="justify" style="line-height: 150%;">
Trọng lượng của sản
phẩm.</div>
</li>
<li>
<div align="justify" style="line-height: 150%;">
Giá trên một đơn vị
tính.</div>
</li>
<li>
<div align="justify" style="line-height: 150%;">
Mô tả thêm về sản
phẩm.</div>
</li>
</ul>
<div align="justify" style="line-height: 150%;">
Thông tin sản phẩm được
hiển thi theo phương thức: Danh sách ảnh các sản phẩm dạng thu nhỏ,
bên dưới mỗi ảnh là tên của sản phẩm đó. Danh sách này được chia
thành nhiều hàng, nhiều cột và số hàng, số cột này có thể hhay đổi
tuỳ ý. Khi kích chuột vào một sản phẩm tuỳ ý trang thông tin chi
tiết về sản phẩm (hình ảnh phóng to về sản phẩm ) cùng các thông tin
khác sẽ thông tin chi tiết cho khách hàng về sản phẩm của họ cần
quan tâm.</div>
</span>
<span style="font-family: Verdana; font-size: 8pt; font-weight: 700;">
<div align="justify" style="line-height: 150%;">
C. Modul phản hồi
(Feedback Form)</div>
</span>
<span style="font-family: Verdana; font-size: 8pt;">
<div align="justify" style="line-height: 150%;">
Phần này sẽ là một mẫu
đăng ký trợ giúp khách hàng gửi các sản phẩm phản hồi của mình về
phía công ty như phản hồi những ý kiến đóng góp về chất lượng dịch
vụ của công ty.</div>
<div align="justify" style="line-height: 150%;">
Khi khách hàng gửi yêu
cầu thì toàn bộ thông tin trên fỏm sẽ được gửi về địa chỉ thư điện
tử ủa công ty đồng thời được lưu vào CSDL để tiện cho việc kiểm tra
theo dõi sau này</div>
</span>
<span style="color: #ce0000; font-family: Verdana; font-size: 8pt; font-weight: 700;">
<div align="justify" style="line-height: 150%;">
D. Modul quảng cáo</div>
</span>
<span style="font-family: Verdana; font-size: 8pt;">
<div align="justify" style="line-height: 150%;">
Nhằm quảng cáo cho các
hoạt động của công ty, bên phải trang chủ của công ty sẽ cho phép
các đại lý của công ty đặt banner của đối tác mà công ty là thành
viên (nếu việc đó là hợp pháp). khi clik huột vào banner sẽ liên kết
đến các site của đại lý, đối tác (nếu có). Trong tương lai, khi quy
mô hoạt động của công ty lớn mạnh, có thể thu hút từ hoạt động đặt
banner quảng cáo.</div>
</span>
<span style="color: #ce0000; font-family: Verdana; font-size: 8pt; font-weight: 700;">
<div align="justify" style="line-height: 150%;">
E. Modul tìm kiếm thông
tin (search)</div>
</span>
<span style="font-family: Verdana; font-size: 8pt;">
<div align="justify" style="line-height: 150%;">
Để tiện cho khách hàng
tra cứu thông tin về sản phẩm, đại lý một cách nhanh nhất. Các thông
tin sẽ được tổ chức sao cho khách hàng tìm thấy thông tin cần thiết
nhanh nhất trong một thời gian ngắn nhất. Khách hàng chỉ cần cập
nhật vào một số tìm kiếm một từ khoá và chọn tìm kiếm trong danh
sách sản phẩm hoặc đại lý. Việc tìm kiếm sẽ tìm ra tất cả các thông
tin chứa khoá tìm kiếm đã nhập vào. Kết quả sẽ được phân trang nếu
số lượng thông tin tìm được nhiều hơn một số lượng đã quy định
(thờng là 30 bản ghi tren một trang thông tin).</div>
</span>
<span style="color: #ce0000; font-family: Verdana; font-size: 8pt; font-weight: 700;">
<div align="justify" style="line-height: 150%;">
F. Modul giỏ hàng</div>
</span>
<span style="font-family: Verdana; font-size: 8pt;">
<div align="justify" style="line-height: 150%;">
Tính năng: Cung cấp cho
khách hàng công cụ bán hàng trực tuyến. Modul này được xây dựng chủ
yếu dành cho các doanh nghiệp có hoạt động kinh doanh, trao đổi hàng
hoá.</div>
<div align="justify" style="line-height: 150%;">
Modul giỏ hang do ECO
thiết kế sẽ làm cho website của bạn hoạt động như một cửa hàng bán
hàng trực tuyến trên mạng Internet. Khách hàng không cần phái đến
tận nơi mà vẫn có thể xem sản phẩm mà bạn cung câp và đặt mua.</div>
</span>
<span style="color: #ce0000; font-family: Verdana; font-size: 8pt; font-weight: 700;">
<div align="justify" style="line-height: 150%;">
G. Modul tư vấn</div>
</span>
<span style="font-family: Verdana; font-size: 8pt;">
<div align="justify" style="line-height: 150%;">
Khi hàng hoá không còn
là thứ khan hiếm trên thị trường thì vấn đề mà người tiêu dùng quan
tâm nhiều nhất là các dịch vụ sau bán hàng, dịch vụ tư vấn về cách
sử dụng …..hiện có nhiều phương thức để nhiều doanh nghiệp thực hiện
việc chăm sóc khách hàng nhưng để tiếp cận và làm thoả mãn những yêu
cầu của khách hàng một cách nhanh nhất và hiệu quả nhất đó là tư vấn
trực tuyến. Modul tư vấn sẽ tư vấn và giải đáp mọi yêu cầu thắc mắc
của khách hàng về sản phẩm mà nhà cung cấp dăng tải trên website của
mình. Modul này dược tổ chức như một danh sách hỏi đáp theo chủ đề.
Khách hàng gửi câu hỏi theo một form yêu cầu. Form này sẽ thu thập
thông tin người gửi và chuyển tới người quản trị website trên cơ sở
đó người quản trị sẽ giải đáp những thắc mắc và gỉ yêu cầu vè địa
chỉ Email của người hỏi. Có thể thông tin được dăng tải, chia sẽ lên
web cho mọi người cùng tham khảo. Tránh trường hợp một câu hỏi được
hỏi nhiều lần.</div>
</span>
<span style="color: #ce0000; font-family: Verdana; font-size: 8pt; font-weight: 700;">
<div align="justify" style="line-height: 150%;">
H. Modul diễn đàn
(Forum form)</div>
</span>
<span style="font-family: Verdana; font-size: 8pt;">
<div align="justify" style="line-height: 150%;">
Yêu cầu về nội dung:</div>
<div align="justify" style="line-height: 150%;">
Là nơi để các bạn đọc
trao dổi ý kiến của mình theo chủ đề. Các chủ dề sẽ được người quản
trị nêu ra hoặc bạn đọc có thể nêu lên chủ đề của mình để mọi người
cùng thảo luận, trao đổi ý kiến. Người dùng sẽ có acount để đăng
nhập và thảo luận trên trang chủ dã nêu ra. Các ý kiến của người
dùng sẽ được thông qua khâu kiểm duyệt trước khi đưa ra cho tất cả
mọi người xem hoăc cho tất cả mọi người xem mà không thông qua khâu
kiểm duyệt. Điều này phụ thuộc vào thời điểm xây dựng chương trình,
quyết định sẽ xây dụng theo phương án nào.</div>
</span>
<span style="font-family: Verdana; font-size: 8pt;">
<div align="justify" style="line-height: 150%;">
Yêu cầu về mặt quản lý
thông tin</div>
</span>
<span style="font-family: Verdana; font-size: 8pt;">
<div align="justify" style="line-height: 150%;">
Diễn đàn được chia
thành nhiều diễn đàn con. Một diễn đàn con do một Admin quản lý. Một
Admin có thể quản lý nhiều diễn đàn con cùng một lúc. Adminvề bản
chât cũng như một user nhưng được phân quyền</div>
<div align="justify" style="line-height: 150%;">
Dịch vụ thiết kế
website do ECO cung cấp cho khách hàng những tiện ích và khả năng mở
rộng như:</div>
<div align="justify" style="line-height: 150%;">
Dễ dàng tương thích với
mọi trình duyệt web, thời gian tải nhanh.</div>
<div align="justify" style="line-height: 150%;">
Nghiên cứu kỹ sở thích
của đối tượng khách hàng truy cập website để đưa ra phương án thiết
kế hopàn hảo.</div>
<div align="justify" style="line-height: 150%;">
Thân thiện với search
engines, dẽ dàng sửa đổi để đạt vị trí cao trên search engines.</div>
<div align="justify" style="line-height: 150%;">
Có khả năng mở rộng và
kết nối với các modul như giỏ hàng, hệ thống châp snhận thanh toán,
hệ thống bám sát khách hàng hay tự động hoá website …..</div>
</span></span><div align="justify" style="line-height: 150%;">
<span style="font-family: Times New Roman; font-size: medium;"><span style="font-family: Verdana; font-size: 8pt;">Khách hàng đã có một
acount cập nhật và sửa đổi thông tin qua truy cập FTP khi thuê chỗ
trên máy chủ của ECO thì ECO chỉ thu phí cập nhật khi khách hàng ó
yêu cầu.</span></span></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-35714712361585933702012-06-16T22:41:00.002+07:002012-06-16T22:41:37.063+07:00Web Server là gì? HTML là gì? PHP là gì?<b>Một trong các công việc đầu tiên của chuyên gia thiết kế Web đó là phải biết về</b><br />
<ul>
<li><b><strong>HMTL</strong>(Ngôn ngữ đánh dấu siêu văn bản)</b></li>
<li><b><strong>Web Programming language</strong> (Ngôn ngữ lập trình Web)</b></li>
<li><b><strong>Web Server</strong> (máy phục vụ Web)</b></li>
<li><b><strong>Database Server</strong> (máy phục vụ Cơ sở dữ liệu).</b></li>
</ul>
<h2>
HTML là gì?<a name='more'></a></h2>
<strong>HTML</strong> (tiếng Anh, viết tắt cho <em>HyperText Markup Language</em>,
tức là “Ngôn ngữ Đánh dấu Siêu văn bản”) là một ngôn ngữ đánh dấu được
thiết kế ra để tạo nên các trang web, nghĩa là các mẩu thông tin được
trình bày trên World Wide Web. Được định nghĩa như là một ứng dụng đơn
giản của <span class="new">SGML</span>, vốn được sử dụng trong các tổ
chức cần đến các yêu cầu xuất bản phức tạp, HTML giờ đây đã trở thành
một chuẩn Internet do tổ chức World Wide Web Consortium (W3C) duy trì.
Phiên bản mới nhất của nó hiện là <strong>HTML 4.01</strong>. Tuy nhiên, HTML hiện không còn được phát triển tiếp. Người ta đã thay thế nó bằng <strong>XHTML.</strong><br />
<h2>
Web Programming Language là gì?</h2>
Web Programming Language (Ngôn ngữ lập trình Web): Ngôn ngữ được viết
theo phong cách lập trình (khác so với HTML – ngôn ngữ đánh dấu) để hỗ
trợ và tăng cường các khả năng của Web. Cho phép điều khiển các phần tử
của trang Web dễ dàng hơn.<br />
Chúng ta có một số ngôn ngữ lập trình Web như là: <strong> ASP</strong>, <strong>ASP.Net</strong>, <strong>PHP, JSP </strong>..<br />
<h2>
Web Server là gì?</h2>
Web Server (máy phục vụ Web): máy tính mà trên đó cài đặt phần mềm
phục vụ Web, đôi khi người ta cũng gọi chính phần mềm đó là Web Server.<br />
Tất cả các Web Server đều hiểu và chạy được các file <span style="color: red; font-weight: bold;"> *.htm</span> và <span style="color: red; font-weight: bold;">*.html</span>, tuy nhiên mỗi Web Server lại phục vụ một số kiểu file chuyên biệt chẳng hạn như IIS của Microsoft dành cho *.<span style="font-weight: bold;">asp</span>, *.<span style="font-weight: bold;">aspx</span>…; Apache dành cho *.<span style="font-weight: bold;">php</span>…; Sun Java System Web Server của SUN dành cho <strong>*.jsp</strong>…<br />
<h2>
Database Server là gì?</h2>
Database server (máy phục vụ Cơ sở dữ liệu): Máy tính mà trên đó có
cài đặt phần mềm Hệ quản trị Cơ sở dữ liệu (HQTCSDL). Chúng ta có một số
HQTCSDL chẳng hạn như: <strong>SQL Server</strong>, <strong> MySQL</strong>, <strong>Oracle</strong>…Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-30769204455709617302012-06-07T06:07:00.000+07:002012-06-07T06:07:05.413+07:00ngôn ngữ SQL và Mysql<h3>
Cơ bản về ngôn ngữ SQL và Mysql</h3>
<a href="http://www.thietkewebso.com/" target="_blank"><img align="left" src="http://www.qhonline.info/data/news/27_04_2009_mysql_logo.jpg" width="150" /> Thiết Kế Web</a>
Mysql là hệ quản trị dữ liệu miễn phí, được tích hợp sử dụng chung
với apache, PHP. Chính yếu tố phát triển trong cộng đồng mã nguồn mở nên
<br />
<a name='more'></a>mysql đã qua rất nhiều sự hỗ trợ của những lập trình viên yêu thích mã
nguồn mở. Mysql cũng có cùng một cách truy xuất và mã lệnh tương tự với
ngôn ngữ SQL. Nhưng Mysql không bao quát toàn bộ những câu truy vấn cao
cấp như SQL. Về bản chất Mysql chỉ đáp ứng việc truy xuất đơn giản trong
quá trình vận hành của website nhưng hầu hết có thể giải quyết các bài
toán trong PHP.<br />
<br />
<strong><span style="color: red;">1- Cách khởi động và sử dụng MYSQL.</span></strong><br />
<br />
Chúng ta sử dụng command như sau:<br />
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
Mysql –hname –uuser –ppass</div>
<br />
Để truy cập vào cơ sở dữ liệu.<br />
Hoặc sử dụng bộ appserv để vào nhanh hơn theo đường dẫn sau:<br />
Start/ Appserv/ Mysql command Line client<br />
Sau đó nhập password mà chúng ta đã đặt vào.<br />
<br />
<strong><span style="color: red;">2- Những định nghĩa cơ bản:</span></strong><br />
<br />
<em><strong>a) Định nghĩa cơ sở dữ liệu, bảng, cột:</strong></em><br />
<br />
Cơ sở dữ liệu: là tên của cơ sở dữ liệu chúng ta muốn sử dụng<br />
Bảng: Là 1 bảng giá trị nằm trong cơ sở dữ liệu.<br />
Cột là 1 giá trị nằm trong bảng. Dùng để lưu trữ các trường dữ liệu.<br />
Thuộc tính <br />
<br />
<span style="text-decoration: underline;">Ví dụ:</span><br />
<br />
<img alt="PHP Example" border="0" src="http://www.qhonline.info/data/example/php_bai_9_01.gif" /><br />
<br />
Như vậy ta có thể hiểu như sau:<br />
1 cơ sở dữ liệu có thể bao gồm nhiều bảng.<br />
1 bảng có thể bao gồm nhiều cột<br />
1 cột có thể có hoặc không có những thuộc tính.<br />
<br />
<strong>b) Định nghĩa 1 số thuật ngữ:</strong><br />
<br />
NULL : Giá trị cho phép rỗng.<br />
AUTO_INCREMENT : Cho phép giá trị tăng dần (tự động).<br />
UNSIGNED : Phải là số nguyên dương<br />
PRIMARY KEY : Cho phép nó là khóa chính trong bảng.<br />
<br />
<strong>c)Loại dữ liệu trong Mysql:</strong><br />
<br />
Ở đây chúng tả chỉ giới thiệu 1 số loại thông dụng: 1 số dữ liệu khác có thể tham khảo trên trang chủ của mysql.<br />
<img alt="PHP Example" border="0" src="http://www.qhonline.info/data/example/php_bai_9_02.gif" width="530" /><br />
<br />
<strong><span style="color: red;">3- Những cú pháp cơ bản:</span></strong><br />
<br />
Cú pháp tạo 1 cơ sở dữ liệu: <br />
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
CREATE DATABASE tên_cơ_sở_dữ_liệu;<br />
Cú pháp sử dụng cơ sở dữ liệu: Use tên_database;<br />
Cú pháp thoát khỏi cơ sở dữ liệu: Exit</div>
<br />
Cú pháp tạo 1 bảng trong cơ sở dữ liệu:<br />
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
CREATE TABLE user (<tên_cột> <mô_tả>,…,<tên_cột_n>…..<mô_tả_n>)</mô_tả_n></tên_cột_n></mô_tả></tên_cột></div>
<br />
<span style="text-decoration: underline;">Ví dụ:</span><br />
<span style="color: darkgreen;"><br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;">mysql>
create table user(user_id INT(15) UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR(255) NOT NULL, password CHAR(50) NOT NULL, email
VARCHAR(200) NOT NULL, PRIMARY KEY (user_id));</span></div>
</span><br />
Hiển thị có bao nhiều bảng: show tables;<br />
Hiển thị có bao nhiêu cột trong bảng: show columns from table;<br />
Thêm 1 cột vào bảng :<br />
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
ALTER TABLE tên_bảng ADD <tên_cột> <thuộc_tính> AFTER <tên_cột></tên_cột></thuộc_tính></tên_cột></div>
<br />
<span style="text-decoration: underline;">Ví dụ:</span><br />
<br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;">mysql> alter table user add sex varchar(200) NOT NULL after email;</span></div>
<br />
<span style="color: red;"><strong>4- Thêm giá trị vào bảng:</strong></span><br />
<br />
<div>
Cú pháp: </div>
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
INSERT INTO Tên_bảng(tên_cột) VALUES(Giá_trị_tương_ứng);</div>
<span style="text-decoration: underline;"><br />
Ví dụ:</span><span style="color: darkgreen;"><br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;">mysql> insert into user(username,password,email,sex,home) values("Lanna","12345"</span><span style="color: darkgreen;">,"lanna@yahoo.com","F","www.abc.com");</span></div>
<br />
<span style="color: red;"><strong>5- Truy xuất dữ liệu:</strong></span></span><br />
<div>
Cú pháp: </div>
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
SELECT tên_cột FROM Tên_bảng;</div>
<span style="text-decoration: underline;"><br />
Ví dụ: </span><span style="color: darkgreen;"><br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;">mysql> select user_id,username from user;</span></div>
</span><br />
<span style="color: red;"><strong>6- Truy xuất dữ liệu với điều kiện:</strong></span><br />
<br />
<div>
Cú pháp: </div>
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
SELECT tên_cột FROM Tên_bảng WHERE điều kiện;</div>
<div>
Ví dụ:</div>
<br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;">mysql> select user_id,username from user where user_id=2;</span></div>
<br />
<span style="color: red;"><strong>7- Truy cập dữ liệu và sắp xếp theo trình tự</strong></span><br />
<br />
Cú pháp: <br />
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
SELECT tên_cột FROM Tên_bảng <br />
WHERE điều kiện (có thể có where hoặc không)<br />
ORDER BY Theo quy ước sắp xếp.</div>
<br />
Trong đó quy ước sắp xếp bao gồm hai thông số là ASC (từ trên xuống dưới), DESC (từ dưới lên trên).<br />
<br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;">mysql> select user_id,username from user order by username ASC ;</span></div>
<br />
<span style="color: red;"><strong>8- Truy cập dữ liệu có giới hạn :</strong></span><br />
<br />
Cú pháp: <br />
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
SELECT tên_cột FROM Tên_bảng <br />
WHERE điều kiện (có thể có where hoặc không)<br />
LIMIT vị trí bắt đầu, số record muốn lấy ra</div>
<br />
<span style="text-decoration: underline;">Ví dụ:</span><br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;">mysql> select user_id,username from user order by username ASC limit 0,10 ;</span></div>
<br />
<strong><span style="color: red;">9- Cập nhật dữ liệu trong bảng:</span></strong><br />
<br />
Cú pháp: <br />
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
Update tên_bảng set tên_cột=Giá trị mới<br />
WHERE (điều kiện).</div>
<br />
Nếu không có ràng buộc điều kiện, chúng sẽ cập nhật toàn bộ giá trị mới của các record trong bảng.<br />
<span style="text-decoration: underline;">Ví dụ:</span><br />
<br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;">mysql> update user set email="admin@qhonline.info" where user_id=1 ;</span></div>
<br />
<strong><span style="color: red;">10- Xóa dữ liệu trong bảng:</span></strong><br />
<br />
Cú pháp: <br />
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
DELETE FROM tên_bảng WHERE (điều kiện).</div>
<br />
Nếu không có ràng buộc điều kiện, chúng sẽ xó toàn bộ giá trị của các record trong bảng.<br />
<br />
<span style="text-decoration: underline;">Ví dụ</span><br />
<span style="color: darkgreen;"><br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;">mysql>delete from user where user_id=1 ;</span></div>
</span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-65039201199624172132012-06-07T06:03:00.002+07:002012-06-07T06:03:45.176+07:00Kết hợp PHP và MYSQL<h3>
Kết hợp PHP và MYSQL trong ứng dụng website</h3>
<img align="left" src="http://www.qhonline.info/data/news/27_04_2009_php_bai_9_00.JPG" width="150" />
chúng ta sẽ cùng tìm hiểu về
cách sử dụng mysql kết hợp với PHP để xuất ra dữ liệu như thế nào.<br />
<a name='more'></a><br />
Để làm việc với mysql và PHP chúng ta cần nắm 6 hàm cơ bản:<br />
<br />
<br />
<strong><span style="color: red;">1- Kết nối cơ sở dữ liệu:</span></strong><br />
<br />
Cú pháp:<br />
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
mysql_connect("hostname","user","pass")</div>
<br />
<strong><span style="color: red;">2- Lựa chọn cơ sở dữ liệu:</span></strong><br />
<br />
Cú pháp:<br />
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
mysql_select_db("tên_CSDL")</div>
<br />
<span style="text-decoration: underline;">Ví dụ:</span><br />
<span style="color: darkgreen;"><br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;">$conn=mysql_connect("localhost","root","root") or die(" khong the ket noi");</span><br />
<span style="color: darkgreen;">mysql_select_db("demo");</span></div>
<br />
<strong><span style="color: red;">3- Thực thi câu lệnh truy vấn:</span></strong></span><br />
Cú pháp:<br />
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
mysql_query("Câu truy vấn ở đây");</div>
<br />
<strong><span style="color: red;">4- Đếm số dòng dữ liệu trong bảng:</span></strong><br />
<br />
Cú pháp:<br />
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
mysql_num_rows();</div>
<br />
<strong><span style="color: red;">5- Lấy dữ liệu từ bảng đưa vào mảng:</span></strong><br />
<br />
Cú pháp:<br />
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
mysql_fetch_array();</div>
<br />
<strong><span style="color: red;">6- Đóng kết nối cơ sở dữ liệu:</span></strong><br />
<br />
Cú pháp:<br />
<br />
<div style="border-bottom: #6b8e23 1px dashed; border-left: #6b8e23 1px dashed; border-right: #6b8e23 1px dashed; border-top: #6b8e23 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
mysql_close();</div>
<br />
<strong><span style="color: red;">Ví dụ áp dụng:</span></strong><br />
<br />
Tạo cơ sở dữ liệu dựa trên từng đoạn code sau:<br />
<span style="color: darkgreen;"><br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;">mysql -hlocalhost -uroot -proot</span><br />
<span style="color: darkgreen;">mysql>create database demo_mysql;</span><br />
<span style="color: darkgreen;">mysql> use demo_mysql;</span><br />
<span style="color: darkgreen;">mysql>create table user(id INT(10)
UNSIGNED NOT NULL AUTO_INCREMENT, username VARCHAR(50) NOT NULL,
password CHAR(50) NOT NULL, PRIMARY KEY(id));</span></div>
</span><br />
Tạo trang test.php. Đầu tiên chúng ta sẽ kết nối cơ sở dữ liệu.<br />
<span style="color: darkgreen;"><br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;"><!--?</span--></span><br />
<span style="color: darkgreen;">$conn=mysql_connect("localhost", "root", "root") or die("can't connect database");</span><br />
<span style="color: darkgreen;">mysql_select_db("demo_mysql",$conn);</span><br />
<span style="color: darkgreen;">?></span></div>
</span><br />
Tiếp đến viết câu truy vấn lấy ra tất cả user từ database.<br />
<span style="color: darkgreen;"><br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;"><!--?</span--></span><br />
<span style="color: darkgreen;">$sql="select * from user";</span><br />
<span style="color: darkgreen;">$query=mysql_query($sql);</span><br />
<span style="color: darkgreen;">?></span></div>
</span><br />
Kiểm tra xem trong bảng dữ liệu đã tồn tại user nào chưa ?. Nếu chưa
thì xuất ra thông báo lỗi, ngược lại thì đưa chúng vào mảng và lặp cho
đến hết bảng dữ liệu.<br />
<span style="color: darkgreen;"><br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;"><!--?</span--></span><br />
<span style="color: darkgreen;">if(mysql_num_rows($query) == 0)</span><br />
<span style="color: darkgreen;">{</span><br />
<span style="color: darkgreen;">echo "Chua co du lieu";</span><br />
<span style="color: darkgreen;">}</span><br />
<span style="color: darkgreen;">else</span><br />
<span style="color: darkgreen;">{</span><br />
<span style="color: darkgreen;">while($row=mysql_fetch_array($query))</span><br />
<span style="color: darkgreen;">{</span><br />
<span style="color: darkgreen;">echo $row[username] ." - ".$row[password]."<br />";</span><br />
<span style="color: darkgreen;">}</span><br />
<span style="color: darkgreen;">}</span><br />
<span style="color: darkgreen;">?></span></div>
</span><br />
Và cuối cùng chúng ta đóng kết nối và kết thúc thao tác xử lý.<br />
<span style="color: darkgreen;"><br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;"><!--?</span--></span><br />
<span style="color: darkgreen;">mysql_close($conn);</span><br />
<span style="color: darkgreen;">?></span></div>
</span><br />
Và cuối cùng là file hoàn chỉnh của ứng dụng trên:<br />
<span style="color: darkgreen;"><br />
<div style="border-bottom: #ff0000 1px dashed; border-left: #ff0000 1px dashed; border-right: #ff0000 1px dashed; border-top: #ff0000 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;"><!--?</span--></span><br />
<span style="color: darkgreen;">$conn=mysql_connect("localhost", "root", "root") or die("can't connect database");</span><br />
<span style="color: darkgreen;">mysql_select_db("demo_mysql",$conn);</span><br />
<span style="color: darkgreen;">$sql="select * from user";</span><br />
<span style="color: darkgreen;">$query=mysql_query($sql);</span><br />
<span style="color: darkgreen;">if(mysql_num_rows($query) == 0)</span><br />
<span style="color: darkgreen;">{</span><br />
<span style="color: darkgreen;">echo "Chua co du lieu";</span><br />
<span style="color: darkgreen;">}</span><br />
<span style="color: darkgreen;">else</span><br />
<span style="color: darkgreen;">{</span><br />
<span style="color: darkgreen;">while($row=mysql_fetch_array($query))</span><br />
<span style="color: darkgreen;">{</span><br />
<span style="color: darkgreen;">echo $row[username] ." - ".$row[password]."<br />";</span><br />
<span style="color: darkgreen;">}</span><br />
<span style="color: darkgreen;">}</span><br />
<span style="color: darkgreen;">mysql_close($conn);</span><br />
<span style="color: darkgreen;">?></span></div>
<br />
<b><span style="color: red;">Tổng kết:</span></b></span><br />
Ở bài này chúng ta đã làm việc với sql và các kỹ thuật kết nối với
database của PHP. Các hàm PHP hỗ trợ mysql hiện nay có rất nhiều. Tuy
nhiên về tính năng cũng như phương thức sử dụng thì chúng cũng giống
nhau. Do vậy các bạn không nên lo lắng khi làm việc với những hàm mà
chúng ta đang nghiên cứu.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-16777793030585416612012-06-07T06:00:00.002+07:002012-06-07T06:00:32.519+07:00Viết ứng dụng đăng nhập bằng PHP và MYSQL<h3 style="color: red;">
Đăng nhập bằng PHP và MYSQL</h3>
<img align="left" src="http://www.qhonline.info/data/news/30_04_2009_php_main_advance_001.jpg" width="150" />
Ở những bài trước chúng ta đã học qua các kiến thức trọng yếu về <strong>PHP</strong>.
Tuy nhiên, để có thể xây dựng một website hoàn chỉnh bằng những kiến
thức đó <br />
<a name='more'></a>thì quả thật không đơn giản. Bởi vì các kiến thức qua sách vở và
tài liệu dù sao cũng chỉ là những kiến thức tổng quát và thiếu tính
khách quan thực tiến. Nên khi người học lập trình bước vào giai đoạn
viết ứng dụng thì thường rất lúng túng. Đó cũng là lý do tôi viết bài
này để hưỡng dẫn các bạn dần làm quen với cách tiếp cận một ứng dụng <strong>PHP và MYSQL</strong> như thế nào.<br />
<br />
Trước hết chúng ta phải thiết kế và xây dựng mô hình cơ sở dữ liệu ứng với từng lệnh bên dưới (xem lại bài <strong><span style="color: red;">ngôn ngữ SQL và MYSQL Căn Bản</span></strong>) sau đó mới tiến hành triển khai lập trình.<br />
<div class="syntaxhighlighter " id="highlighter_180039">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>1</code></td><td class="content"><code class="plain">mysql -hlocalhost -uroot -proot</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>2</code></td><td class="content"><code class="plain">mysql></code><code class="keyword">create</code> <code class="keyword">database</code> <code class="plain">project;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>3</code></td><td class="content"><code class="plain">mysql>use project;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>4</code></td><td class="content"><code class="plain">mysql></code><code class="keyword">create</code> <code class="keyword">table</code> <code class="color2">user</code><code class="plain">( id </code><code class="keyword">INT</code><code class="plain">(10) UNSIGNED </code><code class="color1">NOT</code> <code class="color1">NULL</code> <code class="plain">AUTO_INCREMENT, username </code><code class="keyword">VARCHAR</code><code class="plain">(50) </code><code class="color1">NOT</code> <code class="color1">NULL</code><code class="plain">, </code><code class="keyword">password</code> <code class="keyword">CHAR</code><code class="plain">(50) </code><code class="color1">NOT</code> <code class="color1">NULL</code><code class="plain">, </code><code class="keyword">level</code> <code class="keyword">CHAR</code><code class="plain">(1) </code><code class="color1">NOT</code> <code class="color1">NULL</code><code class="plain">, </code><code class="keyword">PRIMARY</code> <code class="keyword">KEY</code><code class="plain">(id));</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>5</code></td><td class="content"><code class="plain">mysql></code><code class="keyword">insert</code> <code class="keyword">into</code> <code class="color2">user</code><code class="plain">(username,</code><code class="keyword">password</code><code class="plain">,</code><code class="keyword">level</code><code class="plain">) </code><code class="keyword">values</code> <code class="plain">(</code><code class="string">"admin"</code><code class="plain">,</code><code class="string">"12345"</code><code class="plain">,</code><code class="string">"2"</code><code class="plain">) (</code><code class="string">"abc"</code><code class="plain">,</code><code class="string">"12345"</code><code class="plain">,</code><code class="string">"1"</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
</div>
</div>
<div>
Vậy là chúng ta đã có cơ sở dữ liệu như mô hình trên. Tiếp đến chúng ta tạo file <strong>login.php</strong> và thiết kế Form HTML để có màn hình đăng nhập khi người dùng truy cập.</div>
<br />
<div>
</div>
<div class="syntaxhighlighter " id="highlighter_21150">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>1</code></td><td class="content"><code class="plain"><form action="</code">
<code class="string">'login.php'</code> <code class="plain">method=</code><code class="string">'post'</code><code class="plain">></code></form>
</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>2</code></td><td class="content"><code class="plain">Username: <input type="</code" /><code class="string">'text'</code> <code class="plain">name=</code><code class="string">'username'</code> <code class="plain">size=</code><code class="string">'25'</code> <code class="plain">/></code></code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>3</code></td><td class="content"><code class="plain">Password: <input type="</code" /><code class="string">'password'</code> <code class="plain">name=</code><code class="string">'password'</code> <code class="plain">size=</code><code class="string">'25'</code> <code class="plain">/></code></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>4</code></td><td class="content"><code class="plain"><input type="</code" /><code class="string">'submit'</code> <code class="plain">name=</code><code class="string">'ok'</code> <code class="plain">value=</code><code class="string">'Dang Nhap'</code> <code class="plain">/></code></code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>5</code></td><td class="content"><code class="plain"></code></td></tr>
</tbody></table>
</div>
</div>
</div>
Tiếp đến chúng ta tiến hành kiểm tra dữ liệu từ form <br />
<div class="syntaxhighlighter " id="highlighter_499993">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>01</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>02</code></td><td class="content"><code class="keyword">if</code><code class="plain">(isset(</code><code class="variable">$_POST</code><code class="plain">[</code><code class="string">'ok'</code><code class="plain">]))</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>03</code></td><td class="content"><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>04</code></td><td class="content"><code class="variable">$u</code><code class="plain">=</code><code class="variable">$p</code><code class="plain">=</code><code class="string">""</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>05</code></td><td class="content"><code class="spaces"> </code><code class="keyword">if</code><code class="plain">(</code><code class="variable">$_POST</code><code class="plain">[</code><code class="string">'username'</code><code class="plain">] == NULL)</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>06</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>07</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"Please enter your username<br />"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>08</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>09</code></td><td class="content"><code class="spaces"> </code><code class="keyword">else</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>10</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>11</code></td><td class="content"><code class="spaces"> </code><code class="variable">$u</code><code class="plain">=</code><code class="variable">$_POST</code><code class="plain">[</code><code class="string">'username'</code><code class="plain">];</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>12</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>13</code></td><td class="content"><code class="spaces"> </code><code class="keyword">if</code><code class="plain">(</code><code class="variable">$_POST</code><code class="plain">[</code><code class="string">'password'</code><code class="plain">] == NULL)</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>14</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>15</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"Please enter your password<br />"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>16</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>17</code></td><td class="content"><code class="spaces"> </code><code class="keyword">else</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>18</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>19</code></td><td class="content"><code class="spaces"> </code><code class="variable">$p</code><code class="plain">=</code><code class="variable">$_POST</code><code class="plain">[</code><code class="string">'password'</code><code class="plain">];</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>20</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>21</code></td><td class="content"><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>22</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
<span style="color: black;">Đoạn code ở trên sẽ kiểm tra xem người
dùng có tiến hành nhấn nút đăng nhập hay không. Và nếu có thì chúng ta
sẽ xét tiếp tình trạng người dùng có để trống các ô username và password
hay không. Nếu có chúng ta sẽ thông báo lỗi ở bên trên form, để người
sử dụng tiến hành nhập liệu. Vì phiên bản PHP 5.3 trở lên sẽ yêu cầu ta
khai báo biến trước khi sử dụng. Vì thế mặc định ban đầu ta khởi tạo 2
biến $u và $p mang giá trị là rỗng.</span><br />
<br />
Kế đến chúng ta kiểm tra xem có tồn tại hai biến $u và $p (chỉ khi
người dùng đăng nhập thành công thì mới có thể tạo ra 2 biến đó). Tiếp
đến chúng ta tiến hành kết nối cơ sở dữ liệu (xem lại bài <strong><span style="color: red;">kết hợp PHP & MYSQL trong ứng dụng web</span></strong>).<br />
<div class="syntaxhighlighter " id="highlighter_540537">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>1</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>2</code></td><td class="content"><code class="variable">$conn</code><code class="plain">=mysql_connect(</code><code class="string">"localhost"</code><code class="plain">,</code><code class="string">"root"</code><code class="plain">,</code><code class="string">"root"</code><code class="plain">) </code><code class="keyword">or</code> <code class="keyword">die</code><code class="plain">(</code><code class="string">"can't connect this database"</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>3</code></td><td class="content"><code class="plain">mysql_select_db(</code><code class="string">"project"</code><code class="plain">,</code><code class="variable">$conn</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>4</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
Và tiến hành kiểm tra xem username và password người sử dụng vừa nhập
có trùng khớp với thông tin có trong cơ sở dữ liệu hay không ?. Nếu
không thì chúng ta sẽ báo lỗi ngay. Ngược lại sẽ tiến hành lấy dữ liệu
từ bảng và gán vào <strong>session</strong>. Để có thể quản lý phiên làm việc một cách hiệu quả trên mọi trang của khu vực admin (xem lại bài <strong><span style="color: red;">khái niệm cơ bản về cookie và session</span></strong>).<br />
<div class="syntaxhighlighter " id="highlighter_130092">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>01</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>02</code></td><td class="content"><code class="keyword">if</code><code class="plain">(</code><code class="variable">$u</code> <code class="plain">&& </code><code class="variable">$p</code><code class="plain">)</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>03</code></td><td class="content"><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>04</code></td><td class="content"><code class="spaces"> </code><code class="variable">$conn</code><code class="plain">=mysql_connect(</code><code class="string">"localhost"</code><code class="plain">,</code><code class="string">"root"</code><code class="plain">,</code><code class="string">"root"</code><code class="plain">) </code><code class="keyword">or</code> <code class="keyword">die</code><code class="plain">(</code><code class="string">"can't connect this database"</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>05</code></td><td class="content"><code class="spaces"> </code><code class="plain">mysql_select_db(</code><code class="string">"project"</code><code class="plain">,</code><code class="variable">$conn</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>06</code></td><td class="content"><code class="spaces"> </code><code class="variable">$sql</code><code class="plain">=</code><code class="string">"select * from user where username='"</code><code class="plain">.</code><code class="variable">$u</code><code class="plain">.</code><code class="string">"' and password='"</code><code class="plain">.</code><code class="variable">$p</code><code class="plain">.</code><code class="string">"'"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>07</code></td><td class="content"><code class="spaces"> </code><code class="variable">$query</code><code class="plain">=mysql_query(</code><code class="variable">$sql</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>08</code></td><td class="content"><code class="spaces"> </code><code class="keyword">if</code><code class="plain">(mysql_num_rows(</code><code class="variable">$query</code><code class="plain">) == 0)</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>09</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>10</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"Username or password is not correct, please try again"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>11</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>12</code></td><td class="content"><code class="spaces"> </code><code class="keyword">else</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>13</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>14</code></td><td class="content"><code class="spaces"> </code><code class="variable">$row</code><code class="plain">=mysql_fetch_array(</code><code class="variable">$query</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>15</code></td><td class="content"><code class="spaces"> </code><code class="plain">session_start();</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>16</code></td><td class="content"><code class="spaces"> </code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'userid'</code><code class="plain">] = </code><code class="variable">$row</code><code class="plain">[</code><code class="string">'id'</code><code class="plain">];</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>17</code></td><td class="content"><code class="spaces"> </code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'level'</code><code class="plain">] = </code><code class="variable">$row</code><code class="plain">[</code><code class="string">'level'</code><code class="plain">];</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>18</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>19</code></td><td class="content"><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>20</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
<span style="color: black;">Như vậy code hoàn chỉnh cho ứng dụng (file login.php) này là như sau:</span><br />
<div class="syntaxhighlighter " id="highlighter_344719">
<div class="bar show">
<div class="toolbar">
view sourceprint<a class="item about" href="http://www.qhonline.info/php-can-ban/32/bai-11--viet-ung-dung-dang-nhap-bang-php-mysql.html#about" style="height: 16px; width: 16px;" title="?">?</a></div>
</div>
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>01</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>02</code></td><td class="content"><code class="keyword">if</code><code class="plain">(isset(</code><code class="variable">$_POST</code><code class="plain">[</code><code class="string">'ok'</code><code class="plain">]))</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>03</code></td><td class="content"><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>04</code></td><td class="content"><code class="variable">$u</code><code class="plain">=</code><code class="variable">$p</code><code class="plain">=</code><code class="string">""</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>05</code></td><td class="content"><code class="spaces"> </code><code class="keyword">if</code><code class="plain">(</code><code class="variable">$_POST</code><code class="plain">[</code><code class="string">'username'</code><code class="plain">] == NULL)</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>06</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>07</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"Please enter your username<br />"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>08</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>09</code></td><td class="content"><code class="spaces"> </code><code class="keyword">else</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>10</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>11</code></td><td class="content"><code class="spaces"> </code><code class="variable">$u</code><code class="plain">=</code><code class="variable">$_POST</code><code class="plain">[</code><code class="string">'username'</code><code class="plain">];</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>12</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>13</code></td><td class="content"><code class="spaces"> </code><code class="keyword">if</code><code class="plain">(</code><code class="variable">$_POST</code><code class="plain">[</code><code class="string">'password'</code><code class="plain">] == NULL)</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>14</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>15</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"Please enter your password<br />"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>16</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>17</code></td><td class="content"><code class="spaces"> </code><code class="keyword">else</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>18</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>19</code></td><td class="content"><code class="spaces"> </code><code class="variable">$p</code><code class="plain">=</code><code class="variable">$_POST</code><code class="plain">[</code><code class="string">'password'</code><code class="plain">];</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>20</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>21</code></td><td class="content"><code class="spaces"> </code><code class="keyword">if</code><code class="plain">(</code><code class="variable">$u</code> <code class="plain">&& </code><code class="variable">$p</code><code class="plain">)</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>22</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>23</code></td><td class="content"><code class="spaces"> </code><code class="variable">$conn</code><code class="plain">=mysql_connect(</code><code class="string">"localhost"</code><code class="plain">,</code><code class="string">"root"</code><code class="plain">,</code><code class="string">"root"</code><code class="plain">) </code><code class="keyword">or</code> <code class="keyword">die</code><code class="plain">(</code><code class="string">"can't connect this database"</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>24</code></td><td class="content"><code class="spaces"> </code><code class="plain">mysql_select_db(</code><code class="string">"project"</code><code class="plain">,</code><code class="variable">$conn</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>25</code></td><td class="content"><code class="spaces"> </code><code class="variable">$sql</code><code class="plain">=</code><code class="string">"select * from user where username='"</code><code class="plain">.</code><code class="variable">$u</code><code class="plain">.</code><code class="string">"' and password='"</code><code class="plain">.</code><code class="variable">$p</code><code class="plain">.</code><code class="string">"'"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>26</code></td><td class="content"><code class="spaces"> </code><code class="variable">$query</code><code class="plain">=mysql_query(</code><code class="variable">$sql</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>27</code></td><td class="content"><code class="spaces"> </code><code class="keyword">if</code><code class="plain">(mysql_num_rows(</code><code class="variable">$query</code><code class="plain">) == 0)</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>28</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>29</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"Username or password is not correct, please try again"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>30</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>31</code></td><td class="content"><code class="spaces"> </code><code class="keyword">else</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>32</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>33</code></td><td class="content"><code class="spaces"> </code><code class="variable">$row</code><code class="plain">=mysql_fetch_array(</code><code class="variable">$query</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>34</code></td><td class="content"><code class="spaces"> </code><code class="plain">session_start();</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>35</code></td><td class="content"><code class="spaces"> </code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'userid'</code><code class="plain">] = </code><code class="variable">$row</code><code class="plain">[id];</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>36</code></td><td class="content"><code class="spaces"> </code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'level'</code><code class="plain">] = </code><code class="variable">$row</code><code class="plain">[level];</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>37</code></td><td class="content"><code class="spaces"> </code> </td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>38</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>39</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>40</code></td><td class="content"><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>41</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>42</code></td><td class="content"><code class="plain"><form action="</code">
<code class="string">'login.php'</code> <code class="plain">method=</code><code class="string">'post'</code><code class="plain">></code></form>
</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>43</code></td><td class="content"><code class="plain">Username: <input type="</code" /><code class="string">'text'</code> <code class="plain">name=</code><code class="string">'username'</code> <code class="plain">size=</code><code class="string">'25'</code> <code class="plain">/></code></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>44</code></td><td class="content"><code class="plain">Password: <input type="</code" /><code class="string">'password'</code> <code class="plain">name=</code><code class="string">'password'</code> <code class="plain">size=</code><code class="string">'25'</code> <code class="plain">/></code></code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>45</code></td><td class="content"><code class="plain"><input type="</code" /><code class="string">'submit'</code> <code class="plain">name=</code><code class="string">'ok'</code> <code class="plain">value=</code><code class="string">'Dang Nhap'</code> <code class="plain">/></code></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>46</code></td><td class="content"><code class="plain"></code></td></tr>
</tbody></table>
</div>
</div>
</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-48001295563702874162012-06-07T05:55:00.004+07:002012-06-07T05:55:47.918+07:00<h3>
Viết ứng dụng tạo giỏ hàng - shopping cart </h3>
<img align="left" src="http://www.qhonline.info/data/news/26_01_2010_shop_00.gif" width="150" />
<div>
Ở phần 1 tôi đã trình bày phần hiển thị thông tin sách có trong cơ
sở dữ liệu, chu trình thực thi của việc thêm một quyển sách vào giỏ
hàng. Và cơ chế <a name='more'></a>quản lý giỏ hàng của chúng ta như thế nào. Tiếp tục với
phần 2, tôi sẽ trình bày cách quản lý giỏ hàng như chỉnh sửa món hàng,
liệt kê hàng hóa trong giỏ hàng và xóa bỏ từng món hàng hay cả giò hàng
như thế nào. Để có thể hiểu được phần 2. Các bạn vui lòng xem lại <a href="http://www.qhonline.info/php-can-ban/51/bai-19--viet-ung-dung-tao-gio-hang-shopping-cart-phan-1.html" style="color: orangered;" target="_blank" title="bài 19: Viết ứng dụng tạo giỏ hàng – shopping cart – phần 1"><strong></strong></a></div>
<div>
</div>
<div>
<strong><span style="color: orangered; font-size: 14pt;"> Xây dựng hệ thống quản lý giỏ hàng.</span></strong></div>
<div>
</div>
Sau khi đã thêm một món hàng, tại giỏ hàng ta cũng cần phải xử lý để
hiển thị các món hàng đã có trong giỏ. Và như phương pháp ở phần 1,
chúng ta tạm lưu mã sách trong session. (xem lại)
. Vậy ở trang giỏ hàng này, ta sẽ khởi tạo session và sử dụng vòng lặp
duyệt mảng foreach để lặp toàn bộ mã sách đang lưu trong session. Tiếp
tục, ta lại chuyển chúng sang dạng chuỗi bằng hàm implode().<br />
<div class="syntaxhighlighter " id="highlighter_129182">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>1</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>2</code></td><td class="content"><code class="plain">session_start();</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>3</code></td><td class="content"><code class="keyword">foreach</code><code class="plain">(</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">] </code><code class="keyword">as</code> <code class="variable">$key</code><code class="plain">=></code><code class="variable">$value</code><code class="plain">)</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>4</code></td><td class="content"><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>5</code></td><td class="content"><code class="spaces"> </code><code class="variable">$item</code><code class="plain">[]=</code><code class="variable">$key</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>6</code></td><td class="content"><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>7</code></td><td class="content"><code class="variable">$str</code><code class="plain">=implode(</code><code class="string">","</code><code class="plain">,</code><code class="variable">$item</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>8</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
<div>
Giả sử lúc này chuỗi của chúng ta sẽ có dạng 7,8,9. Công việc tiếp
theo là kết nối CSDL để liệt kê các sản phẩm có mã như ở trên. Thay vì sử dụng select * from tên_bảng where id= ??. Thì để tối ưu hơn,
tôi sẽ sử dụng phép in trong SQL. Lúc này câu truy vẫn sẽ tương đương:</div>
<div class="syntaxhighlighter " id="highlighter_271866">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>1</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>2</code></td><td class="content"><code class="variable">$sql</code><code class="plain">=</code><code class="string">"select * from books where id in ('$str') order by id desc"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>3</code></td><td class="content"><code class="variable">$query</code><code class="plain">=mysql_query(</code><code class="variable">$sql</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>4</code></td><td class="content"><code class="keyword">while</code><code class="plain">(</code><code class="variable">$row</code><code class="plain">=mysql_fetch_array(</code><code class="variable">$query</code><code class="plain">))</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>5</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
<div>
Tiếp tục, ta lặp toàn bộ thông tin sách bao gồm tên, tác giả, giá
tiền và cả số lượng mà ta đã lưu trong session là $_SESSION['cart'][
'ID_Món_Hàng']. ID_Món_hàng chính là thông tin ta lặp ra từ CSDL
($row[id]).</div>
<div>
</div>
<div>
Bên cạnh đó tại phần số lượng, ta sẽ đưa giá trị lưu ở session ra
textbox (vì tại giỏ hàng, người dùng được phép điều chỉnh số lượng, nên
lúc này ta cần tạo textbox cho họ điều chỉnh). Vì lặp toàn bộ các quyển
sách nên tại tên tên của textbox số lượng ta cũng cần truyền id để nhận
biết số lượng đó thuộc ID của quyển sách nào.</div>
<div class="syntaxhighlighter " id="highlighter_740574">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>1</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>2</code></td><td class="content"><code class="functions">echo</code> <code class="string">"</code><div align="right">
<code class="string">So Luong: <input cart'][$row[id]]}'="" name="qty[$row[id]]" size="5" type="text" value="{$_SESSION[" /> - "</code><code class="plain">;</code></div>
</td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>3</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
<div>
Chúng ta cũng cho người dùng được phép xóa 1 món hàng nào đó ra
khỏi giỏ hàng của họ. Bằng cách truyền mã quyển sách của từng quyển vào
liên kết delcart.php.</div>
<div class="syntaxhighlighter " id="highlighter_119496">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>1</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>2</code></td><td class="content"><code class="functions">echo</code> <code class="string">"<a href="http://www.blogger.com/delcart.php?productid=$row[id]">Xoa Sach Nay</a><br />
"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>3</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
<div>
Tại đây, ta cũng cần tính luôn giá tiền của từng quyển sách tương
ứng với số lượng mà họ đã chọn. Như vậy, số lượng là phần ta lưu ở
session, còn giá tiền là phần ta lấy ra từ CSDL ứng với mảng $row
($row['price']).</div>
<div class="syntaxhighlighter " id="highlighter_578874">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>1</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>2</code></td><td class="content"><code class="functions">echo</code> <code class="string">"</code><div align="right">
<code class="string"> Gia tien cho mon hang: "</code><code class="plain">. number_format(</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">][</code><code class="variable">$row</code><code class="plain">[id]]*</code><code class="variable">$row</code><code class="plain">[price],3) .</code><code class="string">" VND</code></div>
<code class="string">"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>3</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
Sau cùng, ta cần tính tổng tiền của toàn bộ sản phẩm có trong giỏ hàng. Bằng cách cộng dồn tổng giá tiền của từng món.<br />
<div class="syntaxhighlighter " id="highlighter_20769">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>1</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>2</code></td><td class="content"><code class="variable">$total</code><code class="plain">+=</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">][</code><code class="variable">$row</code><code class="plain">[id]]*</code><code class="variable">$row</code><code class="plain">[price];</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>3</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
<div>
Phần còn lại, là chúng ta hiển thị giá tiền với đúng định dạng VND của Việt Nam.</div>
<div class="syntaxhighlighter " id="highlighter_602471">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>1</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>2</code></td><td class="content"><code class="functions">echo</code> <code class="string">"<b>Tong tien cho cac mon hang: <span style="color: red;">"</span></b></code><b><span style="color: red;"><code class="plain">. number_format(</code><code class="variable">$total</code><code class="plain">,3).</code><code class="string">" VND</code></span></b><code class="string">"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>3</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
<div>
Đồng thời, ta cũng tạo nút cho phép người dùng cập nhật. Và cho phép người dúng xóa toàn bộ giỏ hàng.</div>
<div class="syntaxhighlighter " id="highlighter_304631">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>1</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>2</code></td><td class="content"><code class="functions">echo</code> <code class="string">"<input name="submit" type="submit" value="Cap Nhat Gio Hang" />"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>3</code></td><td class="content"><code class="functions">echo</code> <code class="string">"</code><div align="center" class="pro">
<code class="string">"</code><code class="plain">;</code></div>
</td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>4</code></td><td class="content"><code class="functions">echo</code> <code class="string">"<b><a href="http://www.blogger.com/index.php">Mua Sach Tiep</a> - <a href="http://www.blogger.com/delcart.php?productid=0">Xoa Bo Gio Hang</a></b>"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>5</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
<div>
Như vậy, code đầy đủ sẽ là:</div>
<div class="syntaxhighlighter " id="highlighter_325463">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>01</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>02</code></td><td class="content"><code class="functions">echo</code> <code class="string">"</code><form action="cart.php" method="post">
<code class="string">"</code><code class="plain">;</code></form>
</td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>03</code></td><td class="content"><code class="keyword">foreach</code><code class="plain">(</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">] </code><code class="keyword">as</code> <code class="variable">$key</code><code class="plain">=></code><code class="variable">$value</code><code class="plain">)</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>04</code></td><td class="content"><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>05</code></td><td class="content"><code class="spaces"> </code><code class="variable">$item</code><code class="plain">[]=</code><code class="variable">$key</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>06</code></td><td class="content"><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>07</code></td><td class="content"><code class="variable">$str</code><code class="plain">=implode(</code><code class="string">","</code><code class="plain">,</code><code class="variable">$item</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>08</code></td><td class="content"><code class="variable">$connect</code><code class="plain">=mysql_connect(</code><code class="string">"localhost"</code><code class="plain">,</code><code class="string">"root"</code><code class="plain">,</code><code class="string">"root"</code><code class="plain">) </code><code class="keyword">or</code> <code class="keyword">die</code><code class="plain">(</code><code class="string">"Can not connect database"</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>09</code></td><td class="content"><code class="plain">mysql_select_db(</code><code class="string">"shop"</code><code class="plain">,</code><code class="variable">$connect</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>10</code></td><td class="content"><code class="variable">$sql</code><code class="plain">=</code><code class="string">"select * from books where id in ($str)"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>11</code></td><td class="content"><code class="variable">$query</code><code class="plain">=mysql_query(</code><code class="variable">$sql</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>12</code></td><td class="content"><code class="keyword">while</code><code class="plain">(</code><code class="variable">$row</code><code class="plain">=mysql_fetch_array(</code><code class="variable">$query</code><code class="plain">))</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>13</code></td><td class="content"><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>14</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"</code><div class="pro">
<code class="string">"</code><code class="plain">;</code></div>
</td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>15</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"<h3>
$row[title]</h3>
"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>16</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"Tac gia: $row[author] - Gia: "</code><code class="plain">.number_format(</code><code class="variable">$row</code><code class="plain">[price],3).</code><code class="string">" VND<br />"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>17</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"</code><div align="right">
<code class="string">So Luong: <input cart'][$row[id]]}'="" name="qty[$row[id]]" size="5" type="text" value="{$_SESSION[" /> - "</code><code class="plain">;</code></div>
</td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>18</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"<a href="http://www.blogger.com/delcart.php?productid=$row[id]">Xoa Sach Nay</a><br />
"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>19</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"</code><div align="right">
<code class="string"> Gia tien cho mon hang: "</code><code class="plain">. number_format(</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">][</code><code class="variable">$row</code><code class="plain">[id]]*</code><code class="variable">$row</code><code class="plain">[price],3) .</code><code class="string">" VND</code></div>
<code class="string">"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>20</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">""</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>21</code></td><td class="content"><code class="spaces"> </code><code class="variable">$total</code><code class="plain">+=</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">][</code><code class="variable">$row</code><code class="plain">[id]]*</code><code class="variable">$row</code><code class="plain">[price];</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>22</code></td><td class="content"><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>23</code></td><td class="content"><code class="functions">echo</code> <code class="string">"</code><div align="right" class="pro">
<code class="string">"</code><code class="plain">;</code></div>
</td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>24</code></td><td class="content"><code class="functions">echo</code> <code class="string">"<b>Tong tien cho cac mon hang: <span style="color: red;">"</span></b></code><b><span style="color: red;"><code class="plain">. number_format(</code><code class="variable">$total</code><code class="plain">,3).</code><code class="string">" VND</code></span></b><code class="string">"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>25</code></td><td class="content"><code class="functions">echo</code> <code class="string">""</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>26</code></td><td class="content"><code class="functions">echo</code> <code class="string">"<input name="submit" type="submit" value="Cap Nhat Gio Hang" />"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>27</code></td><td class="content"><code class="functions">echo</code> <code class="string">"</code><div align="center" class="pro">
<code class="string">"</code><code class="plain">;</code></div>
</td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>28</code></td><td class="content"><code class="functions">echo</code> <code class="string">"<b><a href="http://www.blogger.com/index.php">Mua Sach Tiep</a> - <a href="http://www.blogger.com/delcart.php?productid=0">Xoa Bo Gio Hang</a></b>"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>29</code></td><td class="content"><code class="functions">echo</code> <code class="string">""</code><code class="plain">; </code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>30</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
<div>
Sau khi thiết lập thành công trang giỏ hàng cơ bản, lúc này ta đã
có thể thêm sách một cách dễ dàng. Tuy nhiên, giả sử trong trường hợp
không có sách thì sao ?. Chúng ta vẫn chưa xét đến trường hợp giỏ hàng
rỗng thì sẽ như thế nào. Vậy khi nào thì giỏ hàng rỗng ?. Đó là khi
session của giỏ hàng không tồn tại Id của quyển sách nào. Cụ thể,
$_SESSION[‘cart'][id]. Khi id không tồn tại trong session này thì cũng
là lúc giỏ hàng không tồn tại.</div>
<div align="center">
<br />
</div>
<div>
Vậy trước khi cho hiển thị giỏ hàng, ta cần kiểm tra xem có tồn tại
id nào trong giỏ hàng hay không. Và vì id lưu ở dạng mảng đa chiều, nên
ta cần dùng vòng lặp duyệt mảng foreach.</div>
<div>
</div>
<div>
<span style="color: darkgreen;">
<div style="border-bottom: #ff4500 1px dashed; border-left: #ff4500 1px dashed; border-right: #ff4500 1px dashed; border-top: #ff4500 1px dashed; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 520px;">
<span style="color: darkgreen;">foreach($_SESSION[‘cart’] as $k=>$v)</span></div>
</span></div>
<div>
</div>
<div>
Với $k có ý nghĩa tương đương $id quyển sách và $v tương đương là
số lượng của quyển sách trong giỏ hàng. Vậy nếu tồn tại biến $k, thì tức
có nghĩa là trong giỏ hàng có sách.</div>
<div>
</div>
<div class="syntaxhighlighter " id="highlighter_186181">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>01</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>02</code></td><td class="content"><code class="variable">$ok</code><code class="plain">=1;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>03</code></td><td class="content"><code class="keyword">if</code><code class="plain">(isset(</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">]))</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>04</code></td><td class="content"><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>05</code></td><td class="content"><code class="spaces"> </code><code class="keyword">foreach</code><code class="plain">(</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">] </code><code class="keyword">as</code> <code class="variable">$k</code> <code class="plain">=> </code><code class="variable">$v</code><code class="plain">)</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>06</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>07</code></td><td class="content"><code class="spaces"> </code><code class="keyword">if</code><code class="plain">(isset(</code><code class="variable">$k</code><code class="plain">))</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>08</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>09</code></td><td class="content"><code class="spaces"> </code><code class="variable">$ok</code><code class="plain">=2;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>10</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>11</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>12</code></td><td class="content"><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>13</code></td><td class="content"><code class="keyword">if</code><code class="plain">(</code><code class="variable">$ok</code> <code class="plain">== 2)</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>14</code></td><td class="content"><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>15</code></td><td class="content"><code class="comments">// code xử lý giỏ hàng ở trên.</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>16</code></td><td class="content"><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>17</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
<div>
Đoạn code này, ta sử dụng biến $ok để làm biến kiểm tra, mặc định
khi load dữ liệu biến $ok sẽ bằng 1. Và khi trong giỏ hàng tồn tại sách
thì chúng ta sẽ thay đổi biến $ok thành 2. Và gọi giỏ hàng như code ở
trên.</div>
<div>
</div>
<div>
Ở phần trên, ta cũng có đề cập khi người dùng tiến hành chỉnh sửa
số lượng từng món hàng đơn lẻ qua textbox và nhấn cập nhận thì hệ thống
sẽ tiến hành chỉnh sửa lại thông tin giỏ hàng. Vậy chúng ta sẽ xử lý như
thế nào cho trương hợp đó.</div>
<div>
</div>
<div>
Nếu chú ý, các bạn sẽ thấy dòng code chứa textbox cho phép người
dùng nhập số lượng có một tham số đặc biêt là name=qty[$row[id]]. Vậy
tham số này được dùng để làm gì ?.</div>
<div>
</div>
<div>
Tham số này, nói cho chúng ta biết số lượng đang hiển thị là thuộc
mã sản phẩm nào. Vậy khi tiến hành cập nhật giỏ hàng ta sẽ kiểm tra, nếu
$qty[$row[id]] mà có giá trị là 0. Tức là người đó muốn xóa bỏ giỏ
hàng. Ngược lại, ta chỉ viêc cập nhật giỏ hàng $id tương ứng với số
lượng nhập ở textbox.</div>
<div class="syntaxhighlighter " id="highlighter_724056">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>01</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>02</code></td><td class="content"><code class="keyword">if</code><code class="plain">(isset(</code><code class="variable">$_POST</code><code class="plain">[</code><code class="string">'submit'</code><code class="plain">]))</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>03</code></td><td class="content"><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>04</code></td><td class="content"><code class="spaces"> </code><code class="keyword">foreach</code><code class="plain">(</code><code class="variable">$_POST</code><code class="plain">[</code><code class="string">'qty'</code><code class="plain">] </code><code class="keyword">as</code> <code class="variable">$key</code><code class="plain">=></code><code class="variable">$value</code><code class="plain">)</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>05</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>06</code></td><td class="content"><code class="spaces"> </code><code class="keyword">if</code><code class="plain">( (</code><code class="variable">$value</code> <code class="plain">== 0) </code><code class="keyword">and</code> <code class="plain">(</code><code class="functions">is_numeric</code><code class="plain">(</code><code class="variable">$value</code><code class="plain">)))</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>07</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>08</code></td><td class="content"><code class="spaces"> </code><code class="plain">unset (</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">][</code><code class="variable">$key</code><code class="plain">]);</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>09</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>10</code></td><td class="content"><code class="spaces"> </code><code class="keyword">elseif</code><code class="plain">((</code><code class="variable">$value</code> <code class="plain">> 0) </code><code class="keyword">and</code> <code class="plain">(</code><code class="functions">is_numeric</code><code class="plain">(</code><code class="variable">$value</code><code class="plain">)))</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>11</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>12</code></td><td class="content"><code class="spaces"> </code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">][</code><code class="variable">$key</code><code class="plain">]=</code><code class="variable">$value</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>13</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>14</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>15</code></td><td class="content"><code class="spaces"> </code><code class="plain">header(</code><code class="string">"location:cart.php"</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>16</code></td><td class="content"><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>17</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
<div>
Việc xóa món hàng ở trên chỉ đơn giản là hủy bỏ session của id đó.
Việc cập nhật số lượng chỉ đơn giản là gán đè số lượng người nhập (thẻ
value trong textbox) vào số lượng đang lưu trong session.</div>
<div>
</div>
<div>
Vậy code hoàn chỉnh của trang cart.php này sẽ như sau:</div>
<div class="syntaxhighlighter " id="highlighter_329449">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>01</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>02</code></td><td class="content"><code class="plain">session_start();</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>03</code></td><td class="content"><code class="keyword">if</code><code class="plain">(isset(</code><code class="variable">$_POST</code><code class="plain">[</code><code class="string">'submit'</code><code class="plain">]))</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>04</code></td><td class="content"><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>05</code></td><td class="content"><code class="spaces"> </code><code class="keyword">foreach</code><code class="plain">(</code><code class="variable">$_POST</code><code class="plain">[</code><code class="string">'qty'</code><code class="plain">] </code><code class="keyword">as</code> <code class="variable">$key</code><code class="plain">=></code><code class="variable">$value</code><code class="plain">)</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>06</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>07</code></td><td class="content"><code class="spaces"> </code><code class="keyword">if</code><code class="plain">( (</code><code class="variable">$value</code> <code class="plain">== 0) </code><code class="keyword">and</code> <code class="plain">(</code><code class="functions">is_numeric</code><code class="plain">(</code><code class="variable">$value</code><code class="plain">)))</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>08</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>09</code></td><td class="content"><code class="spaces"> </code><code class="plain">unset (</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">][</code><code class="variable">$key</code><code class="plain">]);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>10</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>11</code></td><td class="content"><code class="spaces"> </code><code class="keyword">elseif</code><code class="plain">((</code><code class="variable">$value</code> <code class="plain">> 0) </code><code class="keyword">and</code> <code class="plain">(</code><code class="functions">is_numeric</code><code class="plain">(</code><code class="variable">$value</code><code class="plain">)))</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>12</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>13</code></td><td class="content"><code class="spaces"> </code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">][</code><code class="variable">$key</code><code class="plain">]=</code><code class="variable">$value</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>14</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>15</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>16</code></td><td class="content"><code class="spaces"> </code><code class="plain">header(</code><code class="string">"location:cart.php"</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>17</code></td><td class="content"><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>18</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>19</code></td><td class="content"><code class="plain"></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>20</code></td><td class="content"><code class="plain"></code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>21</code></td><td class="content"><code class="spaces"> </code><code class="plain"><title>Demo Shopping Cart - Created By My Kenny</title></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>22</code></td><td class="content"><code class="spaces"> </code><code class="plain"><link rel="</code"></link><code class="string">"stylesheet"</code> <code class="plain">href=</code><code class="string">"style.css"</code> <code class="plain">/></code></code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>23</code></td><td class="content"><code class="plain"></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>24</code></td><td class="content"><code class="plain"></code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>25</code></td><td class="content"><code class="plain"><h1>
Demo Shopping Cart</h1>
</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>26</code></td><td class="content"><code class="plain"><!--?</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>27</code></td><td class="content"><code class="variable">$ok</code><code class="plain">=1;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>28</code></td><td class="content"><code class="keyword">if</code><code class="plain">(isset(</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">]))</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>29</code></td><td class="content"><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>30</code></td><td class="content"><code class="spaces"> </code><code class="keyword">foreach</code><code class="plain">(</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">] </code><code class="keyword">as</code> <code class="variable">$k</code> <code class="plain">=> </code><code class="variable">$v</code><code class="plain">)</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>31</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>32</code></td><td class="content"><code class="spaces"> </code><code class="keyword">if</code><code class="plain">(isset(</code><code class="variable">$k</code><code class="plain">))</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>33</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>34</code></td><td class="content"><code class="spaces"> </code><code class="variable">$ok</code><code class="plain">=2;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>35</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>36</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>37</code></td><td class="content"><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>38</code></td><td class="content"><code class="keyword">if</code><code class="plain">(</code><code class="variable">$ok</code> <code class="plain">== 2)</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>39</code></td><td class="content"><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>40</code></td><td class="content"> </td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>41</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">""</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>42</code></td><td class="content"><code class="spaces"> </code><code class="keyword">foreach</code><code class="plain">(</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">] </code><code class="keyword">as</code> <code class="variable">$key</code><code class="plain">=></code><code class="variable">$value</code><code class="plain">)</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>43</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>44</code></td><td class="content"><code class="spaces"> </code><code class="variable">$item</code><code class="plain">[]=</code><code class="variable">$key</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>45</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>46</code></td><td class="content"><code class="spaces"> </code><code class="variable">$str</code><code class="plain">=implode(</code><code class="string">","</code><code class="plain">,</code><code class="variable">$item</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>47</code></td><td class="content"><code class="spaces"> </code><code class="variable">$connect</code><code class="plain">=mysql_connect(</code><code class="string">"localhost"</code><code class="plain">,</code><code class="string">"root"</code><code class="plain">,</code><code class="string">"root"</code><code class="plain">) </code><code class="keyword">or</code> <code class="keyword">die</code><code class="plain">(</code><code class="string">"Can not connect database"</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>48</code></td><td class="content"><code class="spaces"> </code><code class="plain">mysql_select_db(</code><code class="string">"shop"</code><code class="plain">,</code><code class="variable">$connect</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>49</code></td><td class="content"><code class="spaces"> </code><code class="variable">$sql</code><code class="plain">=</code><code class="string">"select * from books where id in ($str)"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>50</code></td><td class="content"><code class="spaces"> </code><code class="variable">$query</code><code class="plain">=mysql_query(</code><code class="variable">$sql</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>51</code></td><td class="content"><code class="spaces"> </code><code class="keyword">while</code><code class="plain">(</code><code class="variable">$row</code><code class="plain">=mysql_fetch_array(</code><code class="variable">$query</code><code class="plain">))</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>52</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>53</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"</code><div class="pro">
<code class="string">"</code><code class="plain">;</code></div>
</td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>54</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"<h3>
$row[title]</h3>
"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>55</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"Tac gia: $row[author] - Gia: "</code><code class="plain">.number_format(</code><code class="variable">$row</code><code class="plain">[price],3).</code><code class="string">" VND<br />"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>56</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"</code><div align="right">
<code class="string">So Luong: <input cart'][$row[id]]}'="" name="qty[$row[id]]" size="5" type="text" value="{$_SESSION[" /> - "</code><code class="plain">;</code></div>
</td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>57</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"<a href="http://www.blogger.com/delcart.php?productid=$row[id]">Xoa Sach Nay</a><br />
"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>58</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"</code><div align="right">
<code class="string"> Gia tien cho mon hang: "</code><code class="plain">. number_format(</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">][</code><code class="variable">$row</code><code class="plain">[id]]*</code><code class="variable">$row</code><code class="plain">[price],3) .</code><code class="string">" VND</code></div>
<code class="string">"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>59</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">""</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>60</code></td><td class="content"><code class="spaces"> </code><code class="variable">$total</code><code class="plain">+=</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">][</code><code class="variable">$row</code><code class="plain">[id]]*</code><code class="variable">$row</code><code class="plain">[price];</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>61</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>62</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"</code><div align="right" class="pro">
<code class="string">"</code><code class="plain">;</code></div>
</td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>63</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"<b>Tong tien cho cac mon hang: <span style="color: red;">"</span></b></code><b><span style="color: red;"><code class="plain">. number_format(</code><code class="variable">$total</code><code class="plain">,3).</code><code class="string">" VND</code></span></b><code class="string">"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>64</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">""</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>65</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"<input name="submit" type="submit" value="Cap Nhat Gio Hang" />"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>66</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"</code><div align="center" class="pro">
<code class="string">"</code><code class="plain">;</code></div>
</td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>67</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"<b><a href="http://www.blogger.com/index.php">Mua Sach Tiep</a> - <a href="http://www.blogger.com/delcart.php?productid=0">Xoa Bo Gio Hang</a></b>"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>68</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">""</code><code class="plain">; </code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>69</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>70</code></td><td class="content"><code class="keyword">else</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>71</code></td><td class="content"><code class="spaces"> </code><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>72</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"</code><div class="pro">
<code class="string">"</code><code class="plain">;</code></div>
</td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>73</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">"<div align="center">
Ban khong co mon hang nao trong gio hang<br /><a href="http://www.blogger.com/index.php">Buy Ebook</a></div>
"</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>74</code></td><td class="content"><code class="spaces"> </code><code class="functions">echo</code> <code class="string">""</code><code class="plain">;</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>75</code></td><td class="content"><code class="spaces"> </code><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>76</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>77</code></td><td class="content"><code class="plain"></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>78</code></td><td class="content"><code class="plain"></code></td></tr>
</tbody></table>
</div>
</div>
</div>
<div>
Và cuối cùng, khi người dùng nhấn xóa toàn bộ giỏ hàng hay chỉ xóa
một món hàng, ta sẽ gọi tới trang delcart.php. Vậy trang này sẽ xử lý
như thế nào ?.</div>
<div>
</div>
<div>
Tại đây, ta có thể nhận tham số là: $_GET[‘productid'];</div>
<div>
</div>
<div>
Tham số này sẽ là $id mà chúng truyền qua liên kết. Nếu xóa toàn bộ
giỏ hàng, tức ta sẽ truyền cho nó giá trị bằng 0. Lúc này, ta sẽ hủy
toàn bộ $_SESSION[‘cart']. Ngược lại, nếu là một $id cụ thể, thì ta chỉ
xóa món hàng đó mà thôi. $_SESSION[‘cart'][$id].</div>
<div>
</div>
<div>
Code hoàn chỉnh của file delcart.php như sau:</div>
<div class="syntaxhighlighter " id="highlighter_484097">
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>01</code></td><td class="content"><code class="plain"><!--?php</code--></code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>02</code></td><td class="content"><code class="plain">session_start();</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>03</code></td><td class="content"><code class="variable">$cart</code><code class="plain">=</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">];</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>04</code></td><td class="content"><code class="variable">$id</code><code class="plain">=</code><code class="variable">$_GET</code><code class="plain">[</code><code class="string">'productid'</code><code class="plain">];</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>05</code></td><td class="content"><code class="keyword">if</code><code class="plain">(</code><code class="variable">$id</code> <code class="plain">== 0)</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>06</code></td><td class="content"><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>07</code></td><td class="content"><code class="spaces"> </code><code class="plain">unset(</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">]);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>08</code></td><td class="content"><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>09</code></td><td class="content"><code class="keyword">else</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>10</code></td><td class="content"><code class="plain">{</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>11</code></td><td class="content"><code class="plain">unset(</code><code class="variable">$_SESSION</code><code class="plain">[</code><code class="string">'cart'</code><code class="plain">][</code><code class="variable">$id</code><code class="plain">]);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>12</code></td><td class="content"><code class="plain">}</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>13</code></td><td class="content"><code class="plain">header(</code><code class="string">"location:cart.php"</code><code class="plain">);</code></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><code>14</code></td><td class="content"><code class="functions">exit</code><code class="plain">();</code></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><code>15</code></td><td class="content"><code class="plain">?></code></td></tr>
</tbody></table>
</div>
</div>
</div>
Download toàn bộ mã nguồn của bài này <strong><span style="color: red;"><a href="http://www.qhonline.info/download/example/thietkewebso.rar" target="_blank" title="Bài 20: Viết ứng dụng tạo giỏ hàng - shopping cart - phần 1 và 2">tại đây</a></span></strong><span style="color: red;">.</span><br />
<div>
</div>
Như vậy, chúng ta đã hoàn tất việc xây dựng hoàn chỉnh một hệ thống <strong>shopping cart </strong>đơn giản. Tuy rằng, đây không phải là một bài viết hoàn chỉnh trong việc xây dựng mô hình <strong>thương mại điện tử</strong>. Nhưng quá đó, phần nào giúp các bạn hiểu và dễ dàng phát triển hệ thống của mình có tổ chức hơn.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-85568381297555128402012-06-06T05:57:00.000+07:002012-06-06T05:57:00.555+07:00PHP về hàm<table border="0" cellpadding="0" cellspacing="0"><tbody>
<tr><td id="spanstoryTitle" style="padding-left: 9px;"><span class="story_headline">Khái niệm về hàm và gọi lại hàm trong PHP</span></td>
</tr>
<tr>
<td id="spandatetime" style="padding-left: 9px;"><br /></td>
</tr>
<tr>
<td height="5"><br /></td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td align="left" width="5"><br /></td>
<td align="left" id="tdAvatar" valign="top"><img align="Left" border="0" height="200" hspace="2" src="http://thegioiweb.vn/Uploaded/hangtt/laptrinhweb/072010/PHP_2007.jpg" vspace="2" width="295" /></td>
<td align="left" width="5"><br /></td>
<td align="left" class="story_teaser" id="tdStoryTeaser">Để
giảm thời gian lặp lại 1 thao tác code nhiều lần, PHP hỗ trợ người lập
trình việc tự định nghĩa cho <a name='more'></a>mình những hàm có khả năng lặp lại nhiều
lần trong website. Việc này cũng giúp cho người lập trình kiểm soát mã
nguồn một cách mạch lạc. Đồng thời có thể tùy biến ở mọi trang. Mà không
cần phải khởi tạo hay viết lại mã lệnh như HTML thuần.</td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td id="tdStoryPrice"><br /></td>
</tr>
<tr>
<td height="6"><br /></td>
</tr>
<tr>
<td class="content" id="tdStoryBody"><div style="font-family: Arial;">
<span style="font-size: x-small;"><strong>1- Hàm tự định nghĩa:</strong></span></div>
<span style="font-size: x-small;"><em>Cú pháp:</em></span>
<div style="font-family: Arial;">
<br /></div>
<div style="border: 1px dashed rgb(107, 142, 35); font-family: Arial; padding: 5px; width: 520px;">
<span style="font-size: x-small;">function functiono_name()</span><br />
<span style="font-size: x-small;">{</span><br />
<span style="font-size: x-small;">//Lệnh thực thi</span><br />
<span style="font-size: x-small;">}</span></div>
<div style="font-family: Arial;">
<span style="font-size: x-small;">Tên hàm có thể là một tổ hợp bất kỳ những chứ cái, con số và dấu gạch dưới, nhưng phải bắt đầu từ chứ cái và dấu gạch dưới.</span></div>
<span style="font-size: x-small;">Ví dụ:</span>
<div style="border: 1px dashed rgb(255, 0, 0); font-family: Arial; padding: 5px; width: 520px;">
<span style="font-size: x-small;"><!--?php</font--></span><br />
<span style="font-size: x-small;">
<span style="font-size: x-small;">function name()</span><br />
<span style="font-size: x-small;">{</span><br />
<span style="font-size: x-small;">$name= array("Kenny", "Jiro", "Calvin", "Gillian");</span><br />
<span style="font-size: x-small;">foreach ($name as $test)</span><br />
<span style="font-size: x-small;">{ echo "$test<br />"; }</span><br />
<span style="font-size: x-small;">}</span><br />
<span style="font-size: x-small;">name();</span><br />
<span style="font-size: x-small;">?></span></span></div>
<span style="font-size: x-small;"><span style="font-size: x-small;"><br style="font-family: Arial;" /></span>
<div style="font-family: Arial;">
<span style="font-size: x-small;"><strong>2- Hàm tự định nghĩa với các tham số:</strong></span></div>
<span style="font-size: x-small;"><em>Cú pháp:</em></span>
<div style="font-family: Arial;">
<br /></div>
<div style="border: 1px dashed rgb(107, 142, 35); font-family: Arial; padding: 5px; width: 520px;">
<span style="font-size: x-small;">function function_name($gt1,$gt2)</span><br />
<span style="font-size: x-small;">{</span><br />
<span style="font-size: x-small;">//Hành động</span><br />
<span style="font-size: x-small;">}</span></div>
<span style="font-size: x-small;"><br /></span>
<span style="font-size: x-small;">Ví dụ:</span><br />
<span style="font-size: x-small;"><br style="font-family: Arial;" /></span>
<div style="border: 1px dashed rgb(255, 0, 0); font-family: Arial; padding: 5px; width: 520px;">
<span style="font-size: x-small;"><!--?php</font--></span><br />
<span style="font-size: x-small;">
<span style="font-size: x-small;">function indulieu($text)</span><br />
<span style="font-size: x-small;">{</span><br />
<span style="font-size: x-small;">echo "$text<br />";</span><br />
<span style="font-size: x-small;">}</span><br />
<span style="font-size: x-small;">indulieu("welcome");</span><br />
<span style="font-size: x-small;">indulieu("who are you ?");</span><br />
<span style="font-size: x-small;">?></span></span></div>
<span style="font-size: x-small;"><span style="font-size: x-small;"><br style="font-family: Arial;" /></span>
<div style="font-family: Arial;">
<span style="font-size: x-small;"><strong>3- Hàm tự định nghĩa với giá trị trả về:</strong></span></div>
<span style="font-size: x-small;"><em>Cú pháp: </em></span>
<div style="font-family: Arial;">
<br /></div>
<div style="border: 1px dashed rgb(107, 142, 35); font-family: Arial; padding: 5px; width: 520px;">
<span style="font-size: x-small;">function function_name(Có hoặc không có đối số)</span><br />
<span style="font-size: x-small;">{</span><br />
<span style="font-size: x-small;">//Thuc thi</span><br />
<span style="font-size: x-small;"><strong>return giatri;</strong></span><br />
<span style="font-size: x-small;">}</span></div>
<span style="font-size: x-small;"><br /></span>
<span style="font-size: x-small;">Ví dụ:</span><br />
<span style="font-size: x-small;"><br style="font-family: Arial;" /></span>
<div style="border: 1px dashed rgb(255, 0, 0); font-family: Arial; padding: 5px; width: 520px;">
<span style="font-size: x-small;"><!--?php</font--></span><br />
<span style="font-size: x-small;">
<span style="font-size: x-small;">function tinhtong($a,$b)</span><br />
<span style="font-size: x-small;">{</span><br />
<span style="font-size: x-small;">$total=$a+$b;</span><br />
<span style="font-size: x-small;">return $total;</span><br />
<span style="font-size: x-small;">}</span><br />
<span style="font-size: x-small;">echo tinhtong(19,31)</span><br />
<span style="font-size: x-small;">?></span></span></div>
<span style="font-size: x-small;"><span style="font-size: x-small;"><br style="font-family: Arial;" /></span>
<div style="font-family: Arial;">
<span style="font-size: x-small;"><strong>4-Gọi lại hàm trong PHP:</strong></span></div>
<span style="font-size: x-small;">PHP cung cấp nhiều hàm cho phép triệu gọi lại file. Như hàm include("URL đến file"), require("URL Đến file").</span>
<div style="font-family: Arial;">
<span style="font-size: x-small;">Ngoài hai cú pháp trên còn có include_once(), require_once(). Hai
hàm này cũng có trách nhiệm gọi lại hàm. Những chúng sẽ chỉ gọi lại duy
nhất 1 lần mà thôi.</span></div>
<span style="font-size: x-small;">Ví dụ:</span>
<div style="font-family: Arial;">
<span style="font-size: x-small;">Tạo file top.html với nội dung:</span></div>
<span style="font-size: x-small;"><br /></span>
<div style="border: 1px dashed rgb(255, 0, 0); padding: 5px; width: 520px;">
<span style="font-size: x-small;"><title>Welcome to you</title></span><br />
<span style="font-size: x-small;"></span><br />
<span style="font-size: x-small;"></span><br />
<br />
<span style="font-size: x-small;"></span><br />
<br />
<span style="font-size: x-small;"></span><br />
<br />
<span style="font-size: x-small;"></span><br />
<br />
<span style="font-size: x-small;"></span><br />
<br />
<span style="font-size: x-small;"></span><br />
<br />
<span style="font-size: x-small;"></span><br />
<br />
<span style="font-size: x-small;"></span><br />
<br />
<span style="font-size: x-small;"><br style="font-family: Arial;" /></span><div style="font-family: Arial;">
<span style="font-size: x-small;">Tạo file body.html với nội dung:</span></div>
<span style="font-size: x-small;"><br /></span><div style="border: 1px dashed rgb(255, 0, 0); padding: 5px; width: 520px;">
<span style="font-size: x-small;"></span></div>
<br />
<span style="font-size: x-small;"></span><br />
<br />
<span style="font-size: x-small;"><br style="font-family: Arial;" /></span><div style="font-family: Arial;">
<span style="font-size: x-small;">Tạo file bottom.html với nội dung:</span></div>
<span style="font-size: x-small;"><br /></span><div style="border: 1px dashed rgb(255, 0, 0); padding: 5px; width: 520px;">
<span style="font-size: x-small;"></span></div>
<br />
<span style="font-size: x-small;"></span><br />
<br />
<span style="font-size: x-small;"></span><br />
<br />
<span style="font-size: x-small;"></span><br />
<table border="1" style="width: 700px;">
<tbody>
<tr><td align="center" colspan="5">Banner</td></tr>
<tr>
<td align="center"> Home </td>
<td align="center"> News </td>
<td align="center"> Music </td>
<td align="center"> Download</td>
<td align="center"> Contact</td></tr>
<tr><td align="center" colspan="5"><br />
<span style="font-size: x-small;">Noi dung website</span><br />
<span style="font-size: x-small;"></span></td>
</tr>
<tr>
<td align="center" colspan="5"> Copyright@ abc.com</td>
</tr>
</tbody></table>
<br />
<span style="font-size: x-small;"></span><br />
<span style="font-size: x-small;"></span></div>
<span style="font-size: x-small;"><br style="font-family: Arial;" /></span>
<div style="font-family: Arial;">
<span style="font-size: x-small;">Tạo trang index.php với nội dung:</span></div>
<span style="font-size: x-small;"><br /></span>
<div style="border: 1px dashed rgb(255, 0, 0); padding: 5px; width: 520px;">
<span style="font-size: x-small;"><!--?php</font--></span><br />
<span style="font-size: x-small;">
<span style="font-size: x-small;">include("top.html");</span><br />
<span style="font-size: x-small;">include("body.html");</span><br />
<span style="font-size: x-small;">include("bottom.html");</span><br />
<span style="font-size: x-small;">?></span></span></div>
<span style="font-size: x-small;"><span style="font-size: x-small;"><b style="font-family: Arial;"><br />
Tổng kết:</b>Kết thúc bài học này, hẳn các bạn đã có những khái niệm cơ bản về
hàm và cách sử dụng lại mã PHP. Trên ứng dụng thực tế việc dùng các hàm
để triệu gọi đóng vai trò khá quan trọng, nó giúp mã nguồn của người sử
dụng logic và dễ dàng chỉnh sửa hơn, việc ứng dụng nó trên website như
thế nào cũng sẽ tùy biến hơn so với cách viết trực tiếp trên từng file.</span></span></span></span></span></td></tr>
</tbody></table>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-45019740477652274612012-06-06T05:53:00.000+07:002012-06-06T05:53:32.717+07:00login PHP và MYSQL<table border="0" cellpadding="0" cellspacing="0"><tbody>
<tr><td id="spanstoryTitle" style="padding-left: 9px;"><span class="story_headline" style="font-size: small;">Viết ứng dụng đăng nhập bằng PHP và MYSQL</span></td>
</tr>
<tr>
<td id="spandatetime" style="padding-left: 9px;"><span style="font-size: small;"><br /></span></td>
</tr>
<tr>
<td height="5"><span style="font-size: small;"><br /></span></td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td align="left" width="5"><span style="font-size: small;"><br /></span></td>
<td align="left" id="tdAvatar" valign="top"><span style="font-size: small;"><img align="Left" border="0" height="150" hspace="2" src="http://thegioiweb.vn/Uploaded/hangtt/laptrinhweb/072010/php2107.jpg" vspace="2" width="200" /></span></td>
<td align="left" width="5"><span style="font-size: small;"><br /></span></td>
<td align="left" class="story_teaser" id="tdStoryTeaser"><span style="font-size: small;">Ở
những bài trước chúng ta đã học qua các kiến thức trọng yếu về PHP. Tuy
nhiên, để có thể xây dựng một website hoàn chỉnh bằng <a name='more'></a>những kiến thức
đó thì quả thật không đơn giản. Bởi vì các kiến thức qua sách vở và tài
liệu dù sao cũng chỉ là những kiến thức tổng quát và thiếu tính khách
quan thực tiến. Nên khi người học lập trình bước vào giai đoạn viết ứng
dụng thì thường rất lúng túng. Đó cũng là lý do tôi viết bài này để
hưỡng dẫn các bạn dần làm quen với cách tiếp cận một ứng dụng
PHP&MYSQL như thế nào.</span></td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td id="tdStoryPrice"><span style="font-size: small;"><br /></span></td>
</tr>
<tr>
<td height="6"><span style="font-size: small;"><br /></span></td>
</tr>
<tr>
<td class="content" id="tdStoryBody"><div style="font-family: Arial;">
<span style="font-size: small;">Trước hết chúng ta phải thiết kế và xây dựng mô hình cơ sở dữ liệu ứng với từng lệnh bên dưới (xem lại bài <strong style="color: black;">ngôn ngữ SQL và MYSQL Căn Bản</strong>) sau đó mới tiến hành triển khai lập trình.</span></div>
<div class="syntaxhighlighter sql" id="highlighter_540522" style="font-family: Arial;">
<div class="bar ">
<div class="toolbar">
<span style="font-size: small;"><a class="item about" href="http://www.qhonline.info/php-can-ban/32/bai-11--viet-ung-dung-dang-nhap-bang-php-mysql.html#about" style="height: 16px; width: 16px;" title="?"><br /></a></span></div>
</div>
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>1</code></span></td><td class="content"><span style="font-size: small;"><code class="sql plain">mysql -hlocalhost -uroot -proot</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>2</code></span></td><td class="content"><span style="font-size: small;"><code class="sql plain">mysql></code><code class="sql keyword">create</code> <code class="sql keyword">database</code> <code class="sql plain">project;</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>3</code></span></td><td class="content"><span style="font-size: small;"><code class="sql plain">mysql>use project;</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>4</code></span></td><td class="content"><span style="font-size: small;"><code class="sql plain">mysql></code><code class="sql keyword">create</code> <code class="sql keyword">table</code> <code class="sql color2">user</code><code class="sql plain">( id </code><code class="sql keyword">INT</code><code class="sql plain">(10) UNSIGNED </code><code class="sql color1">NOT</code> <code class="sql color1">NULL</code> <code class="sql plain">AUTO_INCREMENT, username </code><code class="sql keyword">VARCHAR</code><code class="sql plain">(50) </code><code class="sql color1">NOT</code> <code class="sql color1">NULL</code><code class="sql plain">, </code><code class="sql keyword">password</code> <code class="sql keyword">CHAR</code><code class="sql plain">(50) </code><code class="sql color1">NOT</code> <code class="sql color1">NULL</code><code class="sql plain">, </code><code class="sql keyword">level</code> <code class="sql keyword">CHAR</code><code class="sql plain">(1) </code><code class="sql color1">NOT</code> <code class="sql color1">NULL</code><code class="sql plain">, </code><code class="sql keyword">PRIMARY</code><code class="sql keyword">KEY</code><code class="sql plain">(id));</code></span> </td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>5</code></span></td><td class="content"><span style="font-size: small;"><code class="sql plain">mysql></code><code class="sql keyword">insert</code> <code class="sql keyword">into</code> <code class="sql color2">user</code><code class="sql plain">(username,</code><code class="sql keyword">password</code><code class="sql plain">,</code><code class="sql keyword">level</code><code class="sql plain">) </code><code class="sql keyword">values</code> <code class="sql plain">(</code><code class="sql string">"admin"</code><code class="sql plain">,</code><code class="sql string">"12345"</code><code class="sql plain">,</code><code class="sql string">"2"</code><code class="sql plain">) (</code><code class="sql string">"abc"</code><code class="sql plain">,</code><code class="sql string">"12345"</code><code class="sql plain">,</code><code class="sql string">"1"</code><code class="sql plain">);</code></span></td></tr>
</tbody></table>
</div>
</div>
</div>
<div style="font-family: Arial;">
<span style="font-size: small;">Vậy là chúng ta đã có cơ sở dữ liệu như mô hình trên. Tiếp đến
chúng ta thiết kế Form HTML để có màn hình đăng nhập khi người dùng
truy cập.</span></div>
<span style="font-size: small;"><br style="font-family: Arial;" /></span>
<div style="font-family: Arial;">
<span style="font-size: small;"><img alt="Demo Login Example" border="0" src="http://thegioiweb.vn/Uploaded/hangtt/laptrinhweb/072010/php21072.jpg" style="height: 91px; width: 335px;" /></span></div>
<div class="syntaxhighlighter php" id="highlighter_814245" style="font-family: Arial;">
<div class="bar ">
<div class="toolbar">
<span style="font-size: small;"><a class="item about" href="http://www.qhonline.info/php-can-ban/32/bai-11--viet-ung-dung-dang-nhap-bang-php-mysql.html#about" style="height: 16px; width: 16px;" title="?"><br /></a></span></div>
</div>
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>1</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain"></code></span><form action="login.php" method="post">
<span style="font-size: small;"><code class="php plain"></code></span></form>
</td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>2</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">Username: <input name="username" size="25" type="text" /></code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>3</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">Password: <input name="password" size="25" type="password" /></code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>4</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain"><input name="ok" type="submit" value="</code" /><code class="php string">"Dang Nhap"</code> <code class="php plain">/></code></code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>5</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain"></code></span></td></tr>
</tbody></table>
</div>
</div>
</div>
<div style="font-family: Arial;">
<span style="font-size: small;">Tiếp đến chúng ta tiến hành kiểm tra dữ liệu từ form </span></div>
<div class="syntaxhighlighter php" id="highlighter_713040" style="font-family: Arial;">
<div class="bar ">
<div class="toolbar">
<span style="font-size: small;"><a class="item about" href="http://www.qhonline.info/php-can-ban/32/bai-11--viet-ung-dung-dang-nhap-bang-php-mysql.html#about" style="height: 16px; width: 16px;" title="?"><br /></a></span></div>
</div>
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>01</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain"><!--?php</code--></code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>02</code></span></td><td class="content"><span style="font-size: small;"><code class="php keyword">if</code><code class="php plain">(isset(</code><code class="php variable">$_POST</code><code class="php plain">[</code><code class="php string">'ok'</code><code class="php plain">]))</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>03</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>04</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$_POST</code><code class="php plain">[</code><code class="php string">'username'</code><code class="php plain">] == NULL)</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>05</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>06</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php functions">echo</code> <code class="php string">"Please enter your username<br />"</code><code class="php plain">;</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>07</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>08</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php keyword">else</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>09</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>10</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$u</code><code class="php plain">=</code><code class="php variable">$_POST</code><code class="php plain">[</code><code class="php string">'username'</code><code class="php plain">];</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>11</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>12</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$_POST</code><code class="php plain">[</code><code class="php string">'password'</code><code class="php plain">] == NULL)</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>13</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>14</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php functions">echo</code> <code class="php string">"Please enter your password<br />"</code><code class="php plain">;</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>15</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>16</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php keyword">else</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>17</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>18</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$p</code><code class="php plain">=</code><code class="php variable">$_POST</code><code class="php plain">[</code><code class="php string">'password'</code><code class="php plain">];</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>19</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>20</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>21</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">?></code></span></td></tr>
</tbody></table>
</div>
</div>
</div>
<div style="font-family: Arial;">
<span style="font-size: small;"><span style="color: black;">Đoạn code ở trên sẽ kiểm tra xem
người dùng có tiến hành nhấn nút đăng nhập hay không. Và nếu có thì
chúng ta sẽ xét tiếp tình trạng người dùng có để trống các ô username
và password hay không. Nếu có chúng ta sẽ thông báo lỗi ở bên trên
form, để người sử dụng tiến hành nhập liệu.</span></span></div>
<span style="font-size: small;"><br style="font-family: Arial;" /></span>
<div style="font-family: Arial;">
<span style="font-size: small;">Kế đến chúng ta kiểm tra xem có tồn tại hai biến $u và $p (chỉ khi
người dùng đăng nhập thành công thì mới có thể tạo ra 2 biến đó). Tiếp
đến chúng ta tiến hành kết nối cơ sở dữ liệu (xem lại bài <strong style="color: black;">kết hợp PHP & MYSQL trong ứng dụng web</strong>).</span></div>
<div class="syntaxhighlighter php" id="highlighter_725731" style="font-family: Arial;">
<div class="bar ">
<div class="toolbar">
<span style="font-size: small;"><a class="item about" href="http://www.qhonline.info/php-can-ban/32/bai-11--viet-ung-dung-dang-nhap-bang-php-mysql.html#about" style="height: 16px; width: 16px;" title="?"><br /></a></span></div>
</div>
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>1</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain"><!--?php</code--></code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>2</code></span></td><td class="content"><span style="font-size: small;"><code class="php variable">$conn</code><code class="php plain">=mysql_connect(</code><code class="php string">"localhost"</code><code class="php plain">,</code><code class="php string">"root"</code><code class="php plain">,</code><code class="php string">"root"</code><code class="php plain">) </code><code class="php keyword">or</code> <code class="php keyword">die</code><code class="php plain">(</code><code class="php string">"can't connect this database"</code><code class="php plain">);</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>3</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">mysql_select_db(</code><code class="php string">"project"</code><code class="php plain">,</code><code class="php variable">$conn</code><code class="php plain">);</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>4</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">?></code></span></td></tr>
</tbody></table>
</div>
</div>
</div>
<div style="font-family: Arial;">
<span style="font-size: small;">Và tiến hành kiểm tra xem username và password người sử dụng vừa
nhập có trùng khớp với thông tin có trong cơ sở dữ liệu hay không ?.
Nếu không thì chúng ta sẽ báo lỗi ngay. Ngược lại sẽ tiến hành lấy dữ
liệu từ bảng và gán vào session. Để có thể quản lý phiên làm việc một
cách hiệu quả trên mọi trang của khu vực admin (xem lại bài <strong style="color: black;">khái niệm cơ bản về cookie và session</strong><span style="color: black;">).</span></span></div>
<div class="syntaxhighlighter php" id="highlighter_766893" style="font-family: Arial;">
<div class="bar ">
<div class="toolbar">
<span style="font-size: small;"><a class="item about" href="http://www.qhonline.info/php-can-ban/32/bai-11--viet-ung-dung-dang-nhap-bang-php-mysql.html#about" style="height: 16px; width: 16px;" title="?"><br /></a></span></div>
</div>
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>01</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain"><!--?php</code--></code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>02</code></span></td><td class="content"><span style="font-size: small;"><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$u</code> <code class="php plain">&& </code><code class="php variable">$p</code><code class="php plain">)</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>03</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>04</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$conn</code><code class="php plain">=mysql_connect(</code><code class="php string">"localhost"</code><code class="php plain">,</code><code class="php string">"root"</code><code class="php plain">,</code><code class="php string">"root"</code><code class="php plain">) </code><code class="php keyword">or</code> <code class="php keyword">die</code><code class="php plain">(</code><code class="php string">"can't connect this database"</code><code class="php plain">);</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>05</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">mysql_select_db(</code><code class="php string">"project"</code><code class="php plain">,</code><code class="php variable">$conn</code><code class="php plain">);</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>06</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$sql</code><code class="php plain">=</code><code class="php string">"select * from user where username='"</code><code class="php plain">.</code><code class="php variable">$u</code><code class="php plain">.</code><code class="php string">"' and password='"</code><code class="php plain">.</code><code class="php variable">$p</code><code class="php plain">.</code><code class="php string">"'"</code><code class="php plain">;</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>07</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$query</code><code class="php plain">=mysql_query(</code><code class="php variable">$sql</code><code class="php plain">);</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>08</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php keyword">if</code><code class="php plain">(mysql_num_rows(</code><code class="php variable">$query</code><code class="php plain">) == 0)</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>09</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>10</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php functions">echo</code> <code class="php string">"Username or password is not correct, please try again"</code><code class="php plain">;</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>11</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>12</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php keyword">else</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>13</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>14</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$row</code><code class="php plain">=mysql_fetch_array(</code><code class="php variable">$query</code><code class="php plain">);</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>15</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">session_start();</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>16</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">session_register(</code><code class="php string">"userid"</code><code class="php plain">);</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>17</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">session_register(</code><code class="php string">"level"</code><code class="php plain">);</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>18</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$_SESSION</code><code class="php plain">[</code><code class="php string">'userid'</code><code class="php plain">] = </code><code class="php variable">$row</code><code class="php plain">[id];</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>19</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$_SESSION</code><code class="php plain">[</code><code class="php string">'level'</code><code class="php plain">] = </code><code class="php variable">$row</code><code class="php plain">[level];</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>20</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>21</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>22</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">?></code></span></td></tr>
</tbody></table>
</div>
</div>
</div>
<div style="font-family: Arial;">
<span style="font-size: small;"><span style="color: black;">Như vậy code hoàn chỉnh cho ứng dụng này là như sau:</span></span></div>
<div class="syntaxhighlighter php" id="highlighter_65485" style="font-family: Arial;">
<div class="bar ">
<div class="toolbar">
<span style="font-size: small;"><a class="item about" href="http://www.qhonline.info/php-can-ban/32/bai-11--viet-ung-dung-dang-nhap-bang-php-mysql.html#about" style="height: 16px; width: 16px;" title="?"><br /></a></span></div>
</div>
<div class="lines">
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>01</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain"><!--?php</code--></code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>02</code></span></td><td class="content"><span style="font-size: small;"><code class="php keyword">if</code><code class="php plain">(isset(</code><code class="php variable">$_POST</code><code class="php plain">[</code><code class="php string">'ok'</code><code class="php plain">]))</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>03</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>04</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$_POST</code><code class="php plain">[</code><code class="php string">'username'</code><code class="php plain">] == NULL)</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>05</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>06</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php functions">echo</code> <code class="php string">"Please enter your username<br />"</code><code class="php plain">;</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>07</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>08</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php keyword">else</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>09</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>10</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$u</code><code class="php plain">=</code><code class="php variable">$_POST</code><code class="php plain">[</code><code class="php string">'username'</code><code class="php plain">];</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>11</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>12</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$_POST</code><code class="php plain">[</code><code class="php string">'password'</code><code class="php plain">] == NULL)</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>13</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>14</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php functions">echo</code> <code class="php string">"Please enter your password<br />"</code><code class="php plain">;</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>15</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>16</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php keyword">else</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>17</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>18</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$p</code><code class="php plain">=</code><code class="php variable">$_POST</code><code class="php plain">[</code><code class="php string">'password'</code><code class="php plain">];</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>19</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>20</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php keyword">if</code><code class="php plain">(</code><code class="php variable">$u</code> <code class="php plain">&& </code><code class="php variable">$p</code><code class="php plain">)</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>21</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>22</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$conn</code><code class="php plain">=mysql_connect(</code><code class="php string">"localhost"</code><code class="php plain">,</code><code class="php string">"root"</code><code class="php plain">,</code><code class="php string">"root"</code><code class="php plain">) </code><code class="php keyword">or</code> <code class="php keyword">die</code><code class="php plain">(</code><code class="php string">"can't connect this database"</code><code class="php plain">);</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>23</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">mysql_select_db(</code><code class="php string">"project"</code><code class="php plain">,</code><code class="php variable">$conn</code><code class="php plain">);</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>24</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$sql</code><code class="php plain">=</code><code class="php string">"select * from user where username='"</code><code class="php plain">.</code><code class="php variable">$u</code><code class="php plain">.</code><code class="php string">"' and password='"</code><code class="php plain">.</code><code class="php variable">$p</code><code class="php plain">.</code><code class="php string">"'"</code><code class="php plain">;</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>25</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$query</code><code class="php plain">=mysql_query(</code><code class="php variable">$sql</code><code class="php plain">);</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>26</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php keyword">if</code><code class="php plain">(mysql_num_rows(</code><code class="php variable">$query</code><code class="php plain">) == 0)</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>27</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>28</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php functions">echo</code> <code class="php string">"Username or password is not correct, please try again"</code><code class="php plain">;</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>29</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>30</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php keyword">else</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>31</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">{</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>32</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$row</code><code class="php plain">=mysql_fetch_array(</code><code class="php variable">$query</code><code class="php plain">);</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>33</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">session_start();</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>34</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">session_register(</code><code class="php string">"userid"</code><code class="php plain">);</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>35</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">session_register(</code><code class="php string">"level"</code><code class="php plain">);</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>36</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$_SESSION</code><code class="php plain">[</code><code class="php string">'userid'</code><code class="php plain">] = </code><code class="php variable">$row</code><code class="php plain">[id];</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>37</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php variable">$_SESSION</code><code class="php plain">[</code><code class="php string">'level'</code><code class="php plain">] = </code><code class="php variable">$row</code><code class="php plain">[level];</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>38</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code> </span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>39</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>40</code></span></td><td class="content"><span style="font-size: small;"><code class="spaces"> </code><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>41</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">}</code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>42</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">?></code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>43</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain"></code></span><form action="login.php" method="post">
<span style="font-size: small;"><code class="php plain"></code></span></form>
</td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>44</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">Username: <input name="username" size="25" type="text" /></code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>45</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain">Password: <input name="password" size="25" type="password" /></code></span></td></tr>
</tbody></table>
</div>
<div class="line alt2">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>46</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain"><input name="ok" type="submit" value="</code" /><code class="php string">"Dang Nhap"</code> <code class="php plain">/></code></code></span></td></tr>
</tbody></table>
</div>
<div class="line alt1">
<table><tbody>
<tr><td class="number"><span style="font-size: small;"><code>47</code></span></td><td class="content"><span style="font-size: small;"><code class="php plain"></code></span></td></tr>
</tbody></table>
</div>
</div>
</div>
<div style="color: black; font-family: Arial;">
<span style="font-size: small;">Ở bài sau, chúng ta sẽ tiếp tục tìm hiểu <strong>ứng dụng kết hợp PHP & MYSQL cho việc thêm một thành viên</strong><strong> thảo luận tại diễn đàn</strong>. Hoặc thông qua việc <strong>liên hệ của hệ thống websit</strong><strong>e</strong>. Mong sẽ nhận được nhiều ý kiến đóng góp từ các bạn. như thế nào. Mọi sự góp ý, cũng như thắc mắc của các bạn dành cho bài viết vui lòng sử dụng tính năng.</span></div>
</td></tr>
</tbody></table>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-14761380664444016122012-06-06T05:40:00.005+07:002012-06-06T05:40:42.821+07:00CÁC CÂU LỆNH ĐIỂU KHIỂN<div style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;"><strong><br /></strong></span>
</div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana;"><span style="font-size: x-small;"><b>Câu lệnh <i>if</i></b><br />Cú pháp đơn giản nhất của câu lệnh if có dạng như sau:</span></span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">if ( biểu thức )</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Câu lệnh if trên được diễn giải như sau:</span></div>
<a name='more'></a><span style="font-family: Verdana; font-size: x-small;"> nếu <b>biểu thức</b> trả về giá trị TRUE (hoặc tương đương với TRUE sau khi chuyển đổi) thì <b>câu lệnh</b> sẽ được thực thi; ngược lại (khi <b>biểu thức</b> trả về giá trị FALSE) thì bỏ qua không thực thi <b>câu lệnh</b> nữa. </span><br />
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Cú pháp nâng cao của câu lệnh if có dạng như sau:</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">if ( biểu thức )</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh 1;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">else</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh 2;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Câu lệnh if trên được diễn giải như sau: nếu <b>biểu thức</b> trả về giá trị TRUE thì <b>câu lệnh 1</b> sẽ được thi hành, ngược lại thì <b>câu lệnh 2</b> sẽ được thi hành. </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Các lệnh if có thể được lồng vào nhau để tạo ra câu lệnh if phức tạp hơn:</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">if ( biểu thức 1 )</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">if ( biểu thức 2 )</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh 1;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">else</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh 2;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">else</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh 3;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Nếu <b>biểu thức 1</b> trả về giá trị FALSE thì <b>câu lệnh 3</b> sẽ được thực hiện, ngược lại xét tiếp <b>biểu thức 2</b>: nếu <b>biểu thức 2</b> trả về giá trị TRUE thì thực hiện <b>câu lệnh 1</b>, ngược lại nếu <b>biểu thức 2</b> trả về giá trị FALSE thì thực hiện <b>câu lệnh 2</b>.</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">if ( biểu thức 1 )</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh 1;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">else if ( biểu thức 2 )</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh 2;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">else if ( biểu thức 3 )</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh 3;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">else</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh 4;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Nếu <b>biểu thức 1</b> trả về TRUE thì thực hiện <b>câu lệnh 1</b> (các câu lệnh 2,3,4 không thực hiện), nếu <b>biểu thức 1</b> trả về FALSE và <b>biểu thức 2</b> trả về TRUE thì <b>câu lệnh 2</b> được thực hiện, nếu <b>biểu thức 1</b> trả về FALSEm <b>biểu thức 2</b> trả về FALSE và <b>biểu thức 3</b> trả về TRUE thì <b>câu lệnh 3</b> được thực hiện. Nếu cả 3 biểu thức 1,2,3 đều trả về FALSE thì thực hiện <b>câu lệnh 4</b>. </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Ngoài ra PHP còn cung cấp từ khoá <b>elseif</b>, chính là ghép giữa từ khoá else và if.</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana;"><span style="font-size: x-small;"><b>Câu lệnh <i>while</i></b><br />Câu lệnh while dùng để tạo 1 vòng lặp, cú pháp của câu lệnh này như sau: </span></span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">while ( biểu thức )</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Được diễn giải như sau: trong khi <b>biểu thức</b> còn trả về giá trị TRUE thì tiếp tục thực hiện <b>câu lệnh</b>, sau khi thực hiện <b>câu lệnh</b> thì kiểm tra lại <b>biểu thức</b>, nếu vẫn còn trả về giá trị TRUE thì lại tiếp tục thực hiện <b>câu lệnh</b>...cứ tiếp tục như vậy cho tới khi nào biểu thức trả về giá trị FALSE thì ngưng. </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Một ví dụ in ra các số từ 1 tới 10 với câu lệnh while: </span></div>
<div align="justify" style="background-color: lime;">
<b><span style="font-family: Verdana; font-size: x-small;"><!--?php</font--></span></b></div>
<span style="font-family: Verdana; font-size: x-small;">
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">$i = 1;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">while ( $i <= 10 ) {</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo $i, "<b>\n</b>";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">$i++;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana;"><span style="font-size: x-small;">} <i>//end while</i></span></span></div>
<div align="justify" style="background-color: lime;">
<b><span style="font-family: Verdana; font-size: x-small;">?></span></b></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Ghi chú: Câu lệnh <b>$i++</b> tương đương với <b>$i = $i+1;</b>, câu lệnh này sẽ tăng giá trị của $i lên 1 qua mỗi lần lặp. </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana;"><span style="font-size: x-small;"><b>Câu lệnh <i>do-while</i></b><br />Câu lệnh do-while cũng tương tự như câu lệnh white, chỉ khác một điểm là <b>câu lệnh</b> được thực hiện trước rồi <b>biểu thức</b> mới được kiểm tra sau, nếu <b>biểu thức</b> còn trả về giá trị TRUE thì tiếu tục thực hiện <b>câu lệnh</b>. Cú pháp của câu lệnh do-while như sau: </span></span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">do {</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">} while ( biểu thức );</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Một ví dụ in ra các số từ 1 tới 10 với câu lệnh do-while: </span></div>
<div align="justify" style="background-color: lime;">
<b><span style="font-family: Verdana; font-size: x-small;"><!--?php</font--></span></b></div>
<span style="font-family: Verdana; font-size: x-small;">
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">$i = 1;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">do {</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo $i, "<b>\n</b>";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">$i++;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">} while ( $i < 10 );</span></div>
<div align="justify" style="background-color: lime;">
<b><span style="font-family: Verdana; font-size: x-small;">?></span></b></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana;"><span style="font-size: x-small;"><b>Câu lệnh <i>for</i></b><br />Câu lệnh for cũng dùng để tạo vòng lặp. Đây là một trong những câu lệnh phức tạp nhất của PHP, cú pháp của nó như sau: </span></span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">for ( biểu thức 1; biểu thức 2; biểu thức 3 )</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Được diễn giải như sau: </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">· Đầu tiên <b>biểu thức 1</b> được thực hiện, </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">· Tiếp theo <b>biểu thức 2</b> được kiểm tra </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">o Nếu trả về TRUE thì <b>câu lệnh</b> được thực hiện và sau đó thực hiện <b>biểu thức 3</b>. </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">o Nếu trả về FALSE thì kết thúc câu lệnh for. </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">· Kiểm tra lại <b>biểu thức 2</b> và lặp lại quá trình như trên. </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Một ví dụ in ra các số từ 1 tới 10 với câu lệnh for: </span></div>
<div align="justify" style="background-color: lime;">
<b><span style="font-family: Verdana; font-size: x-small;"><!--?php</font--></span></b></div>
<span style="font-family: Verdana; font-size: x-small;">
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">for ( $i = 0; $i < 10; $i++ ) {</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo $i, "<b>\n</b>";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana;"><span style="font-size: x-small;">} <i>//end for</i></span></span></div>
<div align="justify" style="background-color: lime;">
<b><span style="font-family: Verdana; font-size: x-small;">?></span></b></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana;"><span style="font-size: x-small;"><b>Câu lệnh <i>foreach</i></b><br />Câu lệnh foreach chỉ làm việc với array. Câu lệnh foreach có 2 dạng cú pháp như sau: </span></span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">foreach ( $array as $value )</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">foreach ( $array as $key => $value )</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">câu lệnh;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Ta sẽ hiểu rõ hơn 2 dạng cú pháp này qua 2 ví dụ sau:</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Ví dụ 1: </span></div>
<div align="justify" style="background-color: lime;">
<b><span style="font-family: Verdana; font-size: x-small;"><!--?php</font--></span></b></div>
<span style="font-family: Verdana; font-size: x-small;">
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">$a = array('a' => 1, 'b' => '2', 'c' => '3');</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">foreach ( $a as $value ) {</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo $value, "<b>\n</b>";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana;"><span style="font-size: x-small;">} <i>//end foreach</i></span></span></div>
<div align="justify" style="background-color: lime;">
<b><span style="font-family: Verdana; font-size: x-small;">?></span></b></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Chương trình trên sẽ in ra 3 số <b>1</b>, <b>2</b> và <b>3</b>. </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Ví dụ 2: </span></div>
<div align="justify" style="background-color: lime;">
<b><span style="font-family: Verdana; font-size: x-small;"><!--?php</font--></span></b></div>
<span style="font-family: Verdana; font-size: x-small;">
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">$a = array('a' => 1, 'b' => '2', 'c' => '3');</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">foreach ( $a as $key => $value ) {</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo $key, "=", $value, "<b>\n</b>";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana;"><span style="font-size: x-small;">} <i>//end foreach</i></span></span></div>
<div align="justify" style="background-color: lime;">
<b><span style="font-family: Verdana; font-size: x-small;">?></span></b></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Chương trình trên sẽ in ra 3 chuỗi <b>a=1</b>, <b>b=2</b> và <b>c=3</b>. </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana;"><span style="font-size: x-small;"><b>Câu lệnh <i>switch</i></b><br />Câu lệnh switch hoạt động như là 1 loạt câu lệnh if ghép lại với nhau. Ta hãy xem câu lệnh if sau: </span></span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">if ( $a == "abc" )</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo "Giá trị của a là abc";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">} elseif ( $a == "def" )</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo "Giá trị của a là def";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">} elseif ( $a == "123" ) {</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo "Giá trị của a là 123";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">} else {</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo "Giá trị khác";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">} //end if</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">3 câu lệnh if ở trên có thể được viết lại bằng câu lệnh switch như sau: </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">switch ( $a ) {</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">case "abc";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo "Giá trị của a là abc";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">break;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">case "def";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo "Giá trị của a là def";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">break;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">case "123";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo "Giá trị của a là 123";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">break;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">default:</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo "Giá trị khác";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">} //end switch</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana;"><span style="font-size: x-small;"><b>Câu lệnh <i>break</i></b><br />Câu
lệnh break sẽ dừng việc thực thi của các vòng lặp for, foreach, while,
do-while và switch. Ở phần trước ta đã thấy câu lệnh break được sử dụng
trong câu lệnh switch. Nếu không có break, câu lệnh switch ở phần trước
sẽ thành: </span></span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">switch ( $a ) {</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">case "abc";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo "Giá trị của a là abc";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">case "def";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo "Giá trị của a là def";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">case "123";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo "Giá trị của a là 123";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">default:</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo "Giá trị khác";</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">} //end switch</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Nếu giá trị của $a là
"abc" thì cả 4 chuỗi "Giá trị của a là abc", "Giá trị của a là def",
"Giá trị của a là 123" và "Giá trị khác" sẽ được in ra.; nếu $a mang giá
trị "def" thì 3 chuỗi "Giá trị của a là def", "Giá trị của a là 123" và
"Giá trị khác" sẽ được in ra.<br />Ở đây ta muốn chỉ có 1 dòng duy nhất
in ra tương ứng với giá trị của biến $a, nên ta thêm các câu lệnh break
vào các phần case, để khi in ra chuỗi tương ứng với giá trị $a thì ta
thoát ra khỏi câu lệnh switch. </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Một ví dụ sử dụng câu lệnh break trong vòng lặp for: </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">for ( $i=1; $i<=10; $i++ ) {</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo $i;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">if ( $i == 5 ) break;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">}</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Vòng lặp for ở trên
thay vì in ra 10 số từ 1 đến 10, vòng lặp chỉ in ra 5 số từ 1 đến 5 mà
thôi vì khi $i đạt giá trị 5, vòng lặp sẽ kết thúc do câu lệnh break. </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Cách dùng câu lệnh break trong các vòng lặp foreach, while và do-while cũng tương tự.</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana;"><span style="font-size: x-small;"><b>Câu lệnh <i>continue</i></b><br />Câu
lệnh continue áp dụng lên các vòng lặp, lệnh continue sẽ bỏ qua lần lặp
hiện thời và tiếp tục thực hiện các lần lặp tiếp theo. Để hiểu rõ hơn
ta hãy xem ví dụ sau: </span></span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">for ( $i=1; $i<=5; $i++ ) {</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">if ( $i == 2 ) continue;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">echo $i;</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">}</span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Khi $i đạt giá trị 2, câu lệnh <b>echo $i;</b>
sẽ được bỏ qua không thì hành nữa do câu lệnh continue. Và như vậy,
đoạn lệnh trên khi chạy sẽ in ra các giá trị 1,3,4,5 (không có giá trị
2). </span></div>
<div align="justify" style="background-color: lime;">
<span style="font-family: Verdana; font-size: x-small;">Cách dùng của câu lệnh continue trong các vòng lặp foreach, while, do-while cũng tương tự.</span></div>
</span></span></span></span></span>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-77654781876113745242012-06-05T23:18:00.005+07:002012-06-05T23:18:57.901+07:00Một số thành phần cú pháp chính trong JavaScript<h1 class="title" style="background-color: yellow; color: blue;">
</h1>
<div style="background-color: yellow; color: blue;">
<i><em><em><strong>- Khoảng trắng</strong></em></em></i></div>
<div style="background-color: yellow; color: blue;">
<i>Dấu cách, tab và ký tự dòng mới sử dụng bên ngoài một chuỗi ký tự
được gọi là khoảng trắng. Khác với tubor C, khoảng trắng trong
JavaScript có thể ảnh hưởng trực tiếp tới ý nghĩa của câu lệnh. Sử dụng
phương pháp “tự động thêm dấu chấm phẩy”, </i></div>
<a name='more'></a><i>bất cứ một dòng JavaScript nào
thích hợp sẽ được coi là một câu lệnh hợp lệ (giống như có dấu chấm
phẩy trước ký tự dòng mới).</i><br />
<div style="background-color: yellow; color: blue;">
<i>Tuy trong phần lớn trường hợp, dấu chấm phẩy trước khi kết thúc một
dòng JavaScript là không cần thiết để đoạn mã nguồn hoạt động chính xác,
lập trình viên nên sử dụng dấu chấm phẩy sau mỗi câu lệnh để đoạn mã
nguồn dễ nhìn hơn. Ngoài ra, do đặc thù của JavaScript – chuyên dùng
trên trang web, kích cỡ của đoạn mã nguồn là quan trọng, có một số phần
mềm có thể làm giảm kích cỡ của đoạn mã nguồn JavaScript bằng cách bỏ đi
những khoảng trắng không cần thiết, để những phần mềm này hoạt động
chính xác, lập trình viên cần thêm dấu chấm phẩy vào cuối mỗi câu lệnh.</i></div>
<div style="background-color: yellow; color: blue;">
<i><em><strong>- Chú giải</strong></em></i></div>
<div style="background-color: yellow; color: blue;">
<i>Cú pháp chú giải của JavaScript giống với C++. Lập trình viên có thể
chú giải trên nhiều dòng bằng cách bao bọc chú giải với /* và */ hoặc sử
dụng // để chú giải từ vị trí // đến hết dòng.</i></div>
<div style="background-color: yellow; color: blue;">
<i><em><strong>- Biến</strong></em></i></div>
<div style="background-color: yellow; color: blue;">
<i>Trước khi sử dụng biến trong JavaScript, lập trình viên không nhất
thiết phải khai báo biến. Có hai cách để định nghĩa biến trong
JavaScript. Một là sử dụng cú pháp var để khai báo biến:</i></div>
<div style="background-color: yellow; color: blue;">
<i><em><br /> Ngoài ra, lập trình viên có thể chỉ việc gán cho biến một
gía trị để sử dụng biến đó. Biến được định nghĩa ngoài tất cả các hàm
hoặc được sử dụng mà không khai báo với cú pháp var sẽ được coi là biến
toàn cục, những biến này có thể sử dụng trên toàn trang web. Biến được
khai báo với var bên trong một hàm là biến cục bộ của hàm đó và chỉ có
thể sử dụng được bên trong hàm đó.</em></i></div>
<div style="background-color: yellow; color: blue;">
<i><em><strong>- Đối tượng</strong></em></i></div>
<div style="background-color: yellow; color: blue;">
<i>Kiểu của JavaScript được chia ra làm hai loại: kiểu cơ bản và đối tượng.</i></div>
<div style="background-color: yellow; color: blue;">
<i><em>- Đối tượng trong JavaScript là một thực thể có tên xác định và
có thuộc tính trỏ đến giá trị, hàm hoặc cũng có thể là một đối tượng
khác. Có nghĩa là, đối tượng trong JavaScript là một mảng kết hợp
(associative array) tương tự như mảng trong PHP hay từ điển trong
Python, PostScript hoặc Smalltalk.</em></i></div>
<div style="background-color: yellow; color: blue;">
<i>JavaScript có một số đối tượng định nghĩa sẵn, bao gồm mảng (Array),
đối tượng đại số Bool (Boolean), đối tượng ngày tháng (Date), đối tượng
hàm (Function), đối tượng toán học (Math), đối tượng số (Number), đối
tượng đối tượng (Object), đối tượng biểu thức tìm kiếm (RegExp) và đối
tượng chuỗi ký tự (String). Các đối tượng khác là đối tượng thuộc phần
mềm chủ (phần mềm áp dụng JavaScript – thường là trình duyệt).</i></div>
<div style="background-color: yellow; color: blue;">
<i>Bằng cách định nghĩa hàm khởi tạo, lập trình viên có thể tạo đối
tượng. JavaScript là một ngôn ngữ lập trình dựa trên nguyên mẫu do đó
thừa kế diễn ra giữa các đối tượng, không phải giữa các lớp (JavaScript
không hề có lớp). Đối tượng thừa kế thuộc tính từ các nguyên mẫu của
chúng.</i></div>
<div style="background-color: yellow; color: blue;">
<i>Lập trình viên có thể thêm hoặc xóa thuộc tính hoặc hàm trong đối
tượng sau khi đối tượng đã được tạo. Để làm việc này cho tất cả các đối
tượng được tạo từ cùng một hàm khởi tạo, lập trình viên có thể sử dụng
thuộc tính prototype của hàm khởi tạo để truy cập đối tượng nguyên mẫu.
Lập trình viên không nhất thiết phải tự xóa các đối tượng đã tạo,
JavaScript tự động gom rác tất cả những biến không còn được dùng nữa.</i></div>
<div style="background-color: yellow; color: blue;">
<i>Ví dụ:</i></div>
<div style="background-color: yellow; color: blue;">
<i><script language="”JavaScript”">
<br> function samplePrototype() {<br> this.attribute1 = “someValue”; /* thêm một thuộc tính cho đối tượng*/<br> this.attribute2 = 234; /* thêm thuộc tính nữa cho đối tượng*/<br> this.function1 = testFunction; /* thêm một hàm vào đối tượng*/<br> }
</i><p>
<i>function testFunction() {<br> alert(this.attribute2); /*hiển thị 234*/<br> }</i></p>
<p>
<i>var sampleObject = new samplePrototype; /* khởi tạo một đối tượng*/<br> sampleObject.function12(); /* gọi hàm function12 của đối tượng sampleObject*/</i></p>
<p>
<i>sampleObject.attribute3 = 123; /* thêm một thuộc tính nữa cho đối tượng sampleObject*/</i></p>
<p>
<i>delete sampleObject.attribute1; /* xóa bỏ 1 thuộc tính*/<br> delete sampleObject; /* xóa bỏ đối tượng*/<br>
</script></i><br />
</div>
<div style="background-color: yellow; color: blue;">
<i><em><br /><em><strong>- Cấu trúc dữ liệu</strong></em></em></i></div>
<div style="background-color: yellow; color: blue;">
<i>Một cấu trúc dữ liệu tiêu điểm là mảng (Array), mảng trong JavaScript
là một bảng liên kết chỉ mục đến giá trị. Trong JavaScript, tất cả các
đối tượng đều có thể liên kết chỉ mục đến giá trị, nhưng mảng là một đối
tượng đặc biệt có thêm nhiều tính năng xử lý chỉ mục và dữ liệu đặc
biệt (ví dụ: push, join, v.v.)</i></div>
<div style="background-color: yellow; color: blue;">
<i>Mảng trong JavaScript có thuộc tính length. Thuộc tính length của
JavaScript luôn luôn lớn hơn số chỉ mục lớn nhất trong mảng một đơn vị.
Trong phần lớn ngôn ngữ lập trình, những thuộc tính có tính năng như
length thường là thuộc tính chỉ đọc, tuy nhiên, với JavaScript, lập
trình viên có thể thay đổi thuộc tính length. Bằng cách thay đổi thuộc
tính length, lập trình viên có thể làm mảng lớn hơn hoặc nhỏ hơn (và xóa
đi những chỉ mục lớn hơn hoặc bằng thuộc tính length mới).</i></div>
<div style="background-color: yellow; color: blue;">
<i>Mảng trong JavaScript là mảng rải rác, có nghĩa là cho dù lập trình viên có một mảng như sau:</i></div>
<div style="background-color: yellow; color: blue;">
<i><em>Trong trường hợp này, dù mảng có đến chỉ mục mang số 100 thì mảng
cũng chỉ chiếm bộ nhớ của hai số 0 và 5. Tuy nhiên, thuộc tính length
sẽ có giá trị 101 do chỉ mục lớn nhất của mảng trong ví dụ trên là 100.</em></i></div>
<div style="background-color: yellow; color: blue;">
<i>Một số ví dụ về mảng:</i></div>
<div style="background-color: yellow; color: blue;">
<i><em><br /> Lập trình viên cũng có thể định nghĩa cấu trúc bằng đối tượng như sau:</em></i></div>
<div style="background-color: yellow; color: blue;">
<i><em><br /> Cú pháp định nghĩa cấu trúc bằng đối tượng trên có một chuẩn trên danh nghĩa là JSON.</em></i></div>
<div style="background-color: yellow; color: blue;">
<i><em>Chúc bạn thành công</em></i></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-69330562810353228862012-06-05T23:15:00.004+07:002012-06-05T23:15:21.759+07:00Gán và rẽ nhánh trong PHP<h1 class="title" style="background-color: red;">
</h1>
<div style="background-color: red;">
OK, bây giờ chúng ta chuẩn bị làm việc với các câu lệnh “xương sống” của một ngôn ngữ lập trình.<br />
Nếu bạn nào đã từng học qua một ngôn ngữ lập trình nào đó, thì các bạn
có thể đọc lướt qua phần này. Còn nếu bây giờ bạn mới bắt đầu tiếp xúc
với một ngôn ngữ lập trình thì…</div>
<a name='more'></a> hãy đọc kĩ phần này nhé<br />
<div style="background-color: red;">
<strong>- Các câu lệnh trong ngôn ngữ lập trình</strong></div>
<div style="background-color: red;">
Để lập trình giải một bài toán nào đó, chúng ta phải sử dụng các câu lệnh sau:<br /> 1 – Lệnh gán: được sử dụng để đặt một giá trị vào một biến nào đó.<br /> 2 – Lệnh rẽ nhánh: Được sử dụng để xác định xem chương trình sẽ thực hiện công việc gì trong điều kiện ra sao.<br /> 3 – Lệnh lặp: Cho phép chương trình của bạn tự động lặp lại các thao tác nào đó.<br /> Quá trình xây dựng các bước để thực hiện một bài toán nào đó, gọi là quá trình xây dựng thuật giải.</div>
<div style="background-color: red;">
<strong>Ví dụ:</strong></div>
<div style="background-color: red;">
Hãy tưởng tượng bạn đang nhậu<br /> – Bước 0: chưa có ai say rượu.<br /> – Bước 1: Kêu chủ quán cho một chai “cuốc lủi” (tạm thời là lệnh gán).<br /> – Bước 2: Khi còn chưa hết chai thì nhày sang bước 3.<br /> – Bước 3: Mỗi thằng một chén, trăm phần trăm.<br /> – Bước 4: Nếu thằng nào xỉn, thì loại nó ra khỏi trận chiến (lệnh rẽ nhánh).<br /> – Bước 5: Nếu tất cả đều xỉn: tàn cuộc (lệnh rẽ nhánh), còn nếu không thì tiếp tục.<br /> – Bước 6: Nếu hết một chai thì nhảy về bước 1 (Lệnh lặp).</div>
<div style="background-color: red;">
OK, đến giờ thì chắc bạn đã hiểu qua một chút. Bây giờ chúng ta sẽ
ứng dụng chúng vào PHP. Phần về các câu lệnh cơ bản trong PHP được chia
làm 2 bài là Các câu lệnh rẽ nhánh và các câu lệnh lặp. Bài này tập
trung vào việc xử lý câu lệnh gán và rẽ nhánh.</div>
<div style="background-color: red;">
<strong>1 – Lệnh gán</strong>:</div>
<div style="background-color: red;">
Lệnh này đã được học ở bài trước:<br /> Cú pháp:<br /> $ten_bien = gia_tri;<br /><strong>Ví dụ:</strong></div>
<div style="background-color: red;">
$ngay_sinh=”13/4/1992″;<br /> $que_quan=”Thai Nguyen”;<br /> $luong=400000;</div>
<div style="background-color: red;">
<em><strong>2 – Các câu lệnh rẽ nhánh</strong></em><br /> Trong PHP có 2 dạng rẽ nhánh: rẽ hai nhánh (if) và rẽ nhiều nhánh.</div>
<div style="background-color: red;">
Lệnh rẽ nhánh là một trong những câu lệnh quan trọng nhất của tất cả
các ngôn ngữ lập trình. Nó cho phép bạn thực thi một đoạn mã khi mà điều
kiện chỉ định là đúng.</div>
<div style="background-color: red;">
Trong PHP, lệnh rẽ nhánh có dạng sau:</div>
<div style="background-color: red;">
<em>if (điều kiện)</em><br /><em>{</em><br /><em>công việc cần làm</em><br /><em>}</em><br /><strong>Ví dụ:</strong><br /><em>if ($name=”Thiet ke so”)</em><br /><em>{</em><br /><em> echo (“xin chao tat ca cac ban”);</em><br /><em>}</em><br /> Nếu khối câu lệnh cần làm chỉ bao gồm duy nhất một dòng lệnh, ta có thể bỏ cặp dấu {} :</div>
<div style="background-color: red;">
<em>if ($name=”Tung”)</em><br /><em> echo (“Xin chao moi nguoi”);</em><br /> Nhưng nếu nhiều hơn một dòng lệnh, ta phải đưa chúng vào cặp dấu ngoặc {}:</div>
<div style="background-color: red;">
<em>if ($name==”Tung”)</em><br /><em>{</em><br /><em> echo (“Chao tat ca moi chuc”);</em><br /><em> echo (“Chuc ban co 1 ngay tot lanh!”);</em><br /><em>}</em></div>
<div style="background-color: red;">
Đoạn lệnh trên sẽ kiểm tra nếu điều kiện biến $name = “Tung” thì nó sẽ hiển thị lời chào. Còn nếu không thì nó không làm gì cả.</div>
<div style="background-color: red;">
Điều kiện đặt vào có thể là đúng, có thể là sai, có thể là tổng hợp của nhiều điều kiện. Hãy xem ví dụ sau:</div>
<div style="background-color: red;">
<em>if (“false” )</em><br /><em> echo (“Khong co gi ca”);</em></div>
<div style="background-color: red;">
<em>if (($name==”Tung”) && ($pass==”matkhau”))</em><br /><em> echo ($name. “đã nhập đúng mật khẩu”);</em></div>
<div style="background-color: red;">
Đoạn lệnh trên có thể viết tương đương với:</div>
<div style="background-color: red;">
<em>if ($name==”Tung”)</em><br /><em>{</em><br /><em> if ($pass==”matkhau”)</em><br /><em> echo ($name. “đã nhập đúng mật khẩu”);</em><br /><em>}</em></div>
<div style="background-color: red;">
Như bạn thấy ở trên, trong một câu lệnh, chúng ta có thể chèn nhiều
đoạn lệnh khác, người ta gọi đó là cấu trúc khối, tức là trong một khối
lệnh, có thể có chứa nhiều khối lệnh con khác. Nếu bạn phải đọc mã nguồn
của người khác, hi vọng bạn không bị hoa mắt vì hàng chục khối lệnh
chen chúc vào nhau như vậy.</div>
<div style="background-color: red;">
Chúng ta có thể sử dụng các toán tử &&, || hay xor để kết nối các điều kiện với nhau như bạn thấy ở trên</div>
<div style="background-color: red;">
Câu lệnh rẽ nhánh đầy đủ:</div>
<div style="background-color: red;">
Nếu điều kiện kiểm tra trả về false (sai), PHP cho phép chúng ta chỉ định thực thi một khối mã lệnh khác bằng từ khoá else<br /> Ví dụ:<br /> if (($name==”sinh”) && ($pass==”test”))<br /> {<br /> echo (“Good day, “.$name);<br /> }<br /> else<br /> {<br /> echo {“Sai mat khau!”)<br /> }</div>
<div style="background-color: red;">
<em><strong>Chú ý đến một ngoại lệ sau: Trước từ khoá else không bao giờ có dấu chấm phẩy (.</strong></em></div>
<div style="background-color: red;">
<strong><em>Lệnh rẽ nhiều nhánh:</em></strong></div>
<div style="background-color: red;">
Với câu lệnh if, PHP cho phép chúng ta rẽ nhiều nhánh thông qua từ khoá elseif:</div>
<div style="background-color: red;">
if (dieu_kien1)<br /> {<br /> doan_lenh_1;<br /> }<br /> elseif (dieu_kien_2)<br /> {<br /> doan_lenh_2<br /> }<br /> elseif (dieu_kien_3)<br /> } // bao nhiêu từ khoá elseif cũng được<br /> else<br /> {<br /> doan_lenh_n<br /> }</div>
<div style="background-color: red;">
Ví dụ:</div>
<div style="background-color: red;">
if ($thu==2)<br /> {<br /> echo (“Chao co, van, su, ly”);<br /> }<br /> elseif ($thu==3)<br /> {<br /> echo (” Hoa, Sinh, Dia, GDCD”);<br /> }<br /> elseif ($thu==4)<br /> {<br /> echo (“KTCN, Van, Toan, Tieng Anh”);<br /> }<br /> elseif ($thu==5)<br /> {<br /> echo (” Hoa, Toan, Van, Tin”);<br /> }<br /> elseif ($thu==6)<br /> {<br /> echo (“Toan, Van, Anh, Sinh hoat”);<br /> }<br /> else<br /> {<br /> echo (“Duoc di choi”);<br /> }</div>
<div style="background-color: red;">
Trong ví dụ trên, chúng ta đã lặp đi lặp lại thao tác kiểm tra giá
trị của biến $thu, mặc dù nó không thay đổi qua các dòng. Để khắc phục
sự dài dòng này, PHP cho phép ta sử dụng câu lệnh switch. Câu lệnh này
sẽ được sử dụng để kiểm tra khi muốn xem xét qua nhiều giá trị của một
biến:</div>
<div style="background-color: red;">
switch ($bien){<br /> Case gia_tri 1:<br /> doan_lenh_1;<br /> break;<br /> Case gia_tri 2:<br /> doan_lenh_2;<br /> break;<br /> Case gia_tri n:<br /> doan_lenh_n;<br /> break;<br /> default:<br /> doan_lenh_khac;<br /> }</div>
<div style="background-color: red;">
Ví dụ:</div>
<div style="background-color: red;">
switch ($thu){<br /> case 2:<br /> echo (“Chao co, van, su, ly”);<br /> break;<br /> case 3:<br /> echo (” Hoa, Sinh, Dia, GDCD”);<br /> break;<br /> case 4:<br /> echo (“KTCN, Van, Toan, Tieng Anh”);<br /> break;<br /> case 5:<br /> echo (” Hoa, Toan, Van, Tin”);<br /> break;<br /> case 6:<br /> echo (“Toan, Van, Anh, Sinh hoat”);<br /> break;<br /> default:<br /> echo (“Duoc di choi”);<br /> }</div>
<div style="background-color: red;">
Câu lệnh switch sẽ ước lượng giá trị của biến $thu, và so sánh nó với
giá trị của mệnh đề case. Khi một giá trị hợp lệ được tìm thấy, nó sẽ
thực hiện câu lệnh tương ứng với giá trị đó. Còn nếu không, nó sẽ tự
động thực hiện câu lệnh trong mệnh đề default. Hãy chú ý rằng mệnh đề
defaul là tuỳ chọn (bạn có thể có nó hoặc không cần nó)</div>
<div style="background-color: red;">
Chú ý: Sau mỗi mệnh đề trong câu lệnh switch, cần phải sử dụng câu
lệnh break. Nếu không thì chương trình sẽ … thực thi tất tần tật các
đoạn mã lệnh nằm trong câu lệnh switch.</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-3989748476970299182012-06-05T23:13:00.001+07:002012-06-05T23:13:08.966+07:00Đưa website lên google<h1 class="title">
</h1>
<div>
<h1>
Đưa website lên google</h1>
</div>
<div>
Bạn có biết trung bình trên 89% lượng truy cập của một website đều
đến từ Google? Mỗi ngày có hàng triệu người dùng lướt web sử dụng google
để tìm những sản phẩm, dịch vụ và thông tin họ đang cần.</div>
<div style="text-align: center;">
<a href="http://www.thietkewebso.com/" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" target="_blank"><img alt="url google Đưa website lên google" height="210" src="http://www.website.net.vn/wp-content/uploads/2012/03/url-google.jpg" title="url google" width="241" /></a></div>
Nhưng liệu với hàng tỉ website hiện đang tồn tại, làm sao <a href="http://website.net.vn/khach-hang" title="khách hàng">khách hàng</a>
có thể tìm thấy website của bạn trước mà không phải của các đối thủ
cạnh tranh? Search engine optimization (SEO) chính là giải pháp cho vấn
đề trên. SEO bao gồm các kĩ thuật nhằm giúp website đạt thứ hạng cao
trên các cỗ máy tìm kiếm. Chính vì đa phần khách hàng đến 1 website đều
qua google nên nếu bỏ qua công việc này đồng nghĩa với việc bạn mất tiền
mỗi ngày cho website của đối thủ cạnh tranh. Không người dùng nào đủ
kiên nhẫn xem quá 3 trang kết quả sau khi thực hiện tìm kiếm trên
google. Nếu website doanh nghiệp của bạn không nằm trong top 30, khách
hàng sẽ không hề biết website của bạn tồn tại. <br />
<a name='more'></a>Hãy bắt tay vào việc <strong>đưa website lên google</strong> ngay bây giờ.<br />
<strong>Bước 1</strong> : Tạo ra một website : cấu trúc website thì
rất quan trọng. Bạn nên thêm vào một số từ khóa trong menu. Tương tự,
thêm từ khóa trong các category. Tuy nhiên, đừng đặt quá nhiều từ khóa
trong website, Google có thể nghĩ rằng bạn đang spam. Mật độ khoảng
20-40% thì ok. Các keyword phrase nên chứa từ khóa trong đó, footer cũng
vậy.<br />
<strong>Bước 2 </strong>: Mỗi ngày bạn nên viết một bài viết cho các
category hoặc website. Sử dụng một vài yếu tố của bài viết : Title chứa
từ khóa : chính xác và duy nhất. Description có chứa keyword : duy nhất,
không quá dài cũng không quá ngắn. Nội dung có chứ từ khóa : mật độ
khoảng 5-20%. Sử dụng thẻ header, strong, em, achor text, URL đầy đủ
đường dẫn, Alt trong thẻ image, link internal, nofollow. Trong các thẻ
header, file name, alt, URLs nên chứa keywords.<br />
<strong>Bước 3</strong> : Sửa đổi URLs phức tạp như URL dưới đây :
http://www.google.com.vn/search?hl=e…=&oq=&gs_rfai= chuyển thành
như thế này : http://www.google.com.vn/search/seo<br />
<strong>Bước 4</strong> : Redirect đến một version của URLs. Ví dụ :
www sang non-www hoặc ngược lại. Chúng ta cũng nên redirect
yourdomain/index.php hoặc yourdomain/home sang yourdomain bằng cách sử
dụng .htaccess file. Đôi khi bạn muốn giữ rank, PR của URL cũ cho URL
mới, bạn nên redirect cái cũ sang cái mới.<br />
<strong>Bước 5 :</strong> Tạo file robot.txt. Cho phép bot Google truy cập được các content trong website.<br />
<strong>Bước 6 :</strong> Cài đặt Google Analytics để coi tình hình
truy cập website. Sử dụng Webmaster tool để xem Google nhìn site mình
như thế nào. Trong webmaster tool, target site đến địa phương của bạn.<br />
<strong>Bước 7: </strong>Tạo sitemap. Sử dụng xml sitemap hoặc
urllist.txt hoặc bất kỳ dạng sitemap nào mà Google khuyến khích. Kế đến
hãy thêm sitemap vào webmaster tool.<br />
<strong>Bước 8 :</strong> Thêm địa chỉ website vào Google :
http://www.google.com.vn/addurl/?continue=/addurl Để Google index thiết
kế trang web của bạn cần một thời gian (có thể 1-2 ngày hoặc đến 1
tháng). Bạn muốn được index nhanh hơn ? chỉ cần lấy nhiều backlinks tốt
trỏ về site của bạn.<br />
<strong>Bước 9 :</strong> Quảng cáo và lấy backlinks từ những site liên quan. Ví dụ : forum, blog, mạng xã hội, directory, submit article…<br />
<strong>Bước 10 :</strong> Giữ domain và hosting luôn luôn chạy, đừng để 2 thứ này bị trục trặc.<br />
<strong>Bước 11 :</strong> Tiếp tục tạo bài viết và backlinks đến những trang liên quan.<br />
<strong>Bước 12 :</strong> Thường xuyên kiểm tra thứ hạng trên
Google. Hạn chế sử dụng các tools kiểm tra. Khi website nằm trong 1000
kết quả đầu tiên, bạn có thể nghĩ đến nó sẽ xuất hiện trong Quảng cáo
google vào một ngày gần đây.<br />
<strong>Bước 13 :</strong> Tiếp tục làm từ bước 9 đến bước 12, nhớ rằng bước 2 luôn là bước luôn thực hiện thường xuyên.<br />
<strong>Bước 14 :</strong> Top 10 ở bước này. Không còn nghi ngờ,
không ai, và không thứ gì có thể cản trợ bạn. Hãy suy nghĩ về thứ hạng
cao hơn trong top 10. Hãy ao ước nằm trong top 5. Đừng nghĩ bạn sẽ đứng
thứ 1. Điều đó không tốt cho bạn.<br />
<strong>Bước 15 :</strong> Tiếp tục công việc từ bước 9 đến bước 14. Nhớ rằng bước 2 là bước thực hiện thường xuyên.<br />
<strong>Bước 16 :</strong> Cứ tiếp tục công việc kiếm tiền từ website của bạn.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-6620422124647241332012-06-05T23:07:00.006+07:002012-06-05T23:07:46.821+07:00Đưa web thăng hạng trở lại ngay hôm nay!<br />
<div align="center" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;">
<img alt="googlepenguin Đưa web thăng hạng trở lại ngay hôm nay!" border="0" height="145" src="https://lh4.googleusercontent.com/-kmtrXPutKoQ/T6M-nRanwoI/AAAAAAAAB4s/ZqX_8kwGa7s/s200/googlepenguin.jpg" title="Đưa web thăng hạng trở lại ngay hôm nay!" width="200" /></div>
<br />
<h1 class="title">
<br /></h1>
<div class="postdate">
<br /></div>
Sau một đợt nghỉ lễ dài các “cao thủ SEO” của Việt Nam đã
chợt bừng tỉnh giật mình với ác mộng đến từ nam cực của Google, <br />
<a name='more'></a>những
chú chim cánh cụt đã bay về đến Việt Nam.<br />
Một số “cao thủ SEO” vẫn ngồi ung dung trên những quán trà đá vỉa hè,
hô mưa gọi bão rằng, Google thay đổi là chuyện bình thường, một số cao
thủ khác thì tích cực hơn khi nghĩ về việc Google chỉ áp dụng với
Blogspot. Nhưng có lẽ trong thâm tâm thì ai cũng thầm nguyện cầu chim
cánh cụt ko bay vào nhà mình.<br />
Như trước đợt nghỉ lễ 30/4 WEB&SEO đã lưu ý toàn thể anh em làm seo về các thay đổi của Google và 1 vài điều khắc phục như:<br />
1. Rà soát kiểm tra hệ thống liên kết, xem có nhiều từ khóa bị trùng lặp
không, nếu có hãy loại bỏ các liên kết đó. Ví dụ như: Chúng tôi cung
cấp dịch vụ seo giá rẻ, dịch vụ seo chuyên nghiệp, dịch vụ seo google và
bạn chèn các liên kết vào các từ dịch vụ seo.<br />
2. Kiểm tra thiết kế của web xem có nhiều liên kết trùng lặp trong 1
khi vực không và hãy loại bỏ khu vực đó khỏi thiết kế. Chúng thường nằm
trong thẻ <br />
<ul> hoặc . Ví dụ như, máy in canon, máy in
hp, máy in màu, máy in khổ lớn… bạn đang lặp lại từ máy in quá nhiều.<br />
3. Xóa bỏ các nội dung ở 1 trang được sử dụng 2 lần, tức là bạn lặp
lại nội dung, copy nội dung đó, tại 1 page, để làm cho trang của bạn dài
hơi nữa. Hãy loại bỏ những nội dung như thế. Ví dụ như: Trong 1 trang
(1 bài viết, 1 đường dẫn) bạn viết: Sửa điều hòa tại nhà nhanh nhất,(
phần nội dung sửa điều hòa) Sửa điều hòa giá rẻ ( phần nội dung sửa điều
hòa giống phía trên) Sửa điều hòa tại nhà ( phần nội dung sửa điều hòa
giống phía trên)<br />
4. Bỏ hẳn redirect, hide trong thiết kế của bạn. Ví dụ như Khi vào
trang 404 thì chuyển đến trang khác, hay như khi vào trang nội dung là
du học nhật bản thì chuyển đến trang du học mỹ, hoặc như bạn làm ẩn nội
dung du học Mỹ trong trang du học nhật bản…<br />
5. Thay đổi màu sắc và tăng kích thước font chữ lên trên 12px<br />
6. Làm lại một vài backlink ở các trang uy tín và chờ Google index<br />
Chỉ trừng như vậy là đủ để những SEO chân chính có thể yên tâm với thứ hạng của mình trên top Google.<br />
Tuy nhiên, không phải lúc nào Google cũng đúng, và lần này cũng vậy,
vì Google là 1 cái máy, nên họ cũng có những nhầm lẫn nhất định.<br />
Vừa mới đây thôi Google cung cấp cho bạn trang báo cáo nếu web của bạn không phải SPAM nhưng bị Google coi là SPAM<br />
Các bạn có thể truy cập vào
đây: https://docs.google.com/spreadsheet/viewform?formkey=dEVxdmdRWFJRTjRoLWZVTHZkaTBQbkE6MQ&ndplr=1<br />
Tuy nhiên WEB&SEO cũng có cảnh báo tới toàn thể “cao thủ SEO”
rằng, không nên lợi dụng trang báo cáo này khi web của “cao thủ SEO”
đúng là web SPAM. Nó sẽ có những thay đổi tiêu cực được coi là vĩnh
viễn, hơn là những thay đổi tích cực mà “cao thủ SEO” mong muốn nhận
được.<br />
Vậy nên lời khuyên ở đây là các “cao thủ SEO” nên làm theo tuần tự các bước, thay đổi web của mình trước, rồi hãy báo cáo sau.<br />
Xin chân thành cám ơn các bạn đã đọc bài của WEB&SEO. Mọi chia sẻ
có trong bài viết đều là những thông tin có tính chính xác cao và được
xác nhận bởi WEB&SEO, đã thực tế kiểm tra trên 500 website ở hầu
khắp các mảng.<br />
<table>
</table>
</ul>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-64075001809420016092012-06-05T23:06:00.002+07:002012-06-05T23:06:07.936+07:00Làm thế nào để biết website của tôi có cần thiết kế lại không?<h1 class="title" style="background-color: yellow;">
</h1>
<div style="background-color: yellow;">
Nếu website của bạn gặp phải bất cứ vấn đề nào về SEO thì bạn nên thiết kế lại, điều đó mang lại doanh thu tiềm năng cho bạn.<br />
Có thể bạn có một website đẹp với sự thiết kế thành công, </div>
<a name='more'></a>song lại chưa
tính đến những nguyên tắc về tối ưu hóa công cụ tìm kiếm (SEO) hoặc một
website cũ, hoạt động tốt, nói cho mọi người biết về công ty của bạn,
nhưng tải chậm và nội dung ít cập nhật. Trong những trường hợp này bạn
nên thiết kế lại website của mình.<br />
<div style="background-color: yellow;">
Cả 2 website trên sẽ tranh chấp để dành được lưu lượng truy cập.
Website thiết kế tốt có thể dành được lưu lượng truy cập , đặc biệt là
những người truy cập trực tiếp trang đó, nhưng đối với những người sử
dụng từ khóa tìm kiếm sản phẩm và dịch vụ của bạn thì lại không thể tìm
ra nó.</div>
<div style="background-color: yellow;">
Một website cũ hơn với nội dung lạc hậu cũng sẽ thất bại bởi các công
cụ tìm kiếm cho rằng nó không tồn tại hoặc đã ngừng hoạt động (vì thiếu
tin tức mới). Cả 2 website này đều có lưu lượng truy cập lớn và tăng
khả năng sinh lời trong kinh doanh, nhưng nếu thiếu SEO thì sẽ làm giảm
một phần doanh thu có thể.</div>
<div style="background-color: yellow;">
Cần thiết kế lại những yếu tố nào trên website?</div>
<div style="background-color: yellow;">
<strong>Tất cả Flash</strong></div>
<div style="background-color: yellow;">
Mặc dù có những tiến bộ đáng kể trong công nghệ Search Engine và
chúng bắt đầu đọc một số dạng flash, một site chứa toàn flash có thể
không được Search Engines lập chỉ mục. Các website này rất đẹp nhưng các
công cụ tìm kiếm sẽ không đánh giá chúng cao bởi vì nội dung này không
thể đọc được. Vậy các công ty lớn có xếp hạng cao mà có các site toàn
chứa flash thì sao? Những website này có một mức độ liên kết cao nên nội
dung chứa flash của chúng có lẽ không gây ra vấn đề gì, nếu bạn không
phải một công ty lớn, một website chứa toàn flash sẽ không tốt.</div>
<div style="background-color: yellow;">
<strong>Frames</strong></div>
<div style="background-color: yellow;">
Các frame trên website sẽ khiến các công cụ tìm kiếm gặp khó khăn khi
lập chỉ mục cho website đó. Hơn nữa những người khách truy cập cũng
thường không mấy ưa chuộng các frame này bởi chúng khiến họ khó đọc và
không ấn tượng với trang web của bạn. Một số trình duyệt còn không hỗ
trợ các frame khiến các khách hàng tiềm năng hoàn toàn không đọc được trang web của bạn.</div>
<div style="background-color: yellow;">
<strong>Các Splash page</strong></div>
<div style="background-color: yellow;">
Các nhà thiết kế dùng splash pages để tạo tác động trực quan tới
khách thăm. Hãy tưởng tượng rằng toàn bộ webpage giống như trang hoạt
ảnh sinh động. Thật ấn tượng. Nhưng đáng tiếc , theo góc nhìn của SEO
thì chúng thật khủng khiếp. Nói chung, các splash page chứa rất ít hoặc
không có nội dung text và cũng không có cả các đường link nhưng lại chứa
nhiều các flash page và phần mềm khác. Điều này khiến các Search Engine
vẫn khó xếp hạng cho website của bạn.Vì vậy, bạn có thể ấn tượng với
các splash page của mình nhưng chính chúng lại làm rất nhiều các khách
hàng tiềm năng “ chối bỏ” trang web của bạn .</div>
<div style="background-color: yellow;">
<strong>Tải chậm</strong></div>
<div style="background-color: yellow;">
Thường thì một trang web tải chậm gây cản trở cho cả các khách truy
cập và search engine. Bởi các khách thăm không đủ kiên nhẫn để chờ tải
các trang và hầu hết các search engine luôn xếp hạng cho các trang tải
nhanh hơn là một trang tải chậm. Vì vậy, bạn cần sự thay thế nếu các
trang trên website của bạn tải chậm.<br /><strong><br /> Nội dung lỗi thời</strong></div>
<div style="background-color: yellow;">
Trước hết, các search engine sẽ hoàn toàn không để ý loại trang web
này nếu nó không còn tồn tại. Có thể trước đây nó vẫn được chấp nhận cả
khi không cập nhật nội dung hàng tháng, nhưng lúc này nó sẽ bị bỏ qua
nếu nội dung không cập nhật thường xuyên. Bởi nội dung cũ kỹ sẽ không
thu hút khách truy cập của bạn.</div>
<div style="background-color: yellow;">
Nếu website của bạn gặp phải bất cứ vấn đề nào về SEO như ở trên thì
bạn cần triển khai thiết kế lại; Điều đó mang lại doanh thu tiềm năng
cho bạn.</div>
<div style="background-color: yellow;">
Thiết kế số chúc bạn thành công,</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-48764499707464098362012-06-05T23:03:00.003+07:002012-06-05T23:03:56.832+07:00Chọn tiêu đề tối ưu cho bài viết – Seo websites<h1 class="title">
<br /></h1>
(Quang cao google) Bất cứ bài viết nào cũng đều phải có tiêu đề trang
để giới thiệu nội dung muốn đề cập đến trong bài viết đó. Việc tối ưu
tiêu đề bài viết vì thế rất quan trọng, nó là mấu chốt để người dùng tìm
kiếm thông tin cần thiết trên mạng. Sau đây là bí quyết chọn tiêu đề
tối ưu cho bài viết :<br />
<a href="http://www.thietkewebso.com/" target="_blank"><img alt="seo Chọn tiêu đề tối ưu cho bài viết Seo websites" class="aligncenter" height="263" src="http://www.website.net.vn/wp-content/uploads/2012/02/seo.jpg" title="seo" width="350" /> webso</a><br />
<strong>1. Google hiển thị từ 60 đến 70 ký tự đầu tiên của tiêu đề</strong> <strong>trong trang kết quả tìm</strong> <strong>kiếm</strong><br />
<a name='more'></a><strong>.</strong> Vì
thế bạn hãy đặt các từ khóa quan trọng nhất trong phần đầu tiên của
tiêu đề bài viết và các từ khóa tìm kiếm quan trọng hơn nằm lùi về phía
sau. Nếu tiêu đề bài viết của bạn dài quá 70 ký tự, Google sẽ cắt bớt;
Google chỉ lấy đến ký tự thứ 69 và thay thế dấu ba chấm “…” cho phần còn
lại của tiêu đề.<br />
<strong>2.</strong> <strong>Thay vì bắt đầu tiêu đề của bài viết bằng một loạt từ khóa, thì bạn nên</strong> <strong>thêm các ký tự mang tính chất miêu tả</strong>, <strong>cung cấp thông tin về nội dung và đặt trước từ</strong> <strong>khóa quan trọng.</strong> Điều
này sẽ giúp bài viết vượt qua bộ lọc của Google trong kết quả tìm kiếm
(Và đương nhiên nó sẽ có thứ hạng ổn định hơn), trong khi mang lại thêm
cho bạn thứ hạng cao đối với những từ khóa phụ (chứa trong phần đầu tiên
của tiêu đề).<br />
<strong>3. Tiêu đề trang</strong> <strong>là một trong số ít thông tin mà Google cung cấp cho người dùng trong trang kết quả tìm kiếm</strong> trước
khi người tìm kiếm chọn để hiển thị nội dung. Ví thế, tiêu đề bài viết
là yếu tố quan trọng để thu hút sự chú ý của người tìm kiếm và kích
thích họ nhắp chọn xem nội dung giữa rất nhiều trang kết quả khác của
các đối thủ cạnh tranh. Đây là yếu tố quyết định và là cơ hội tạo ra sự
khác biệt giữa chính bạn và các đối thủ khác về mặt chất lượng.<br />
<strong>4. Tiêu đề tốt</strong> <strong>sẽ tạo ra ý muốn trả lời và đặt câu hỏi, kích thích người đọc.</strong><br />
<strong>5.</strong> <strong>Tiêu đề bài viết là một trong những yếu tố duy nhất</strong> mà
công cụ tìm kiếm hiển thị cho người tìm kiếm trước khi xem nội dung
trang, nên chúng sẽ gán trọng số cao cho các từ xuất hiện trên tiêu đề.
Thêm nữa, rất nhiều người khi liên kết tới trang sẽ sử dụng tiêu đề bài
viết như là ký tự liên kết (anchor text).<br />
<strong>6. Việc chèn các từ khóa một cách trùng lặp, giống nhau một cách hợp lý và dễ đọc</strong> <strong>cho phép bạn cải thiện độ tin cậy của chuỗi các từ khóa.</strong> Tuy
nhiên, những từ khóa này phải được sắp xếp có ý nghĩa và dễ đọc cho
người tìm kiếm chứ không phải cho bọ tìm kiếm. Thay vì nhồi nhét danh
sách từ khóa vào trong phần tiêu đề thì bạn nên trình bày tiêu đề rõ
ràng và mang tính miêu tả nội dung, sản phẩm hay dịch vụ website của bạn.<br />
<strong>7. Đánh giá sai tiềm năng khách hàng</strong> <strong>bằng việc cung ứng các dịch vụ không tương thích</strong> <strong>sẽ làm giảm tỉ lệ chuyển đổi và lãng phí thời gian phục vụ cho các đối</strong> <strong>tượng không phải là khách hàng tiềm năng. </strong>Ví dụ, nếu sản phẩm của bạn là các mặt hàng cao cấp thì website của bạn không cần phải tối ưu, quảng bá website với các từ khóa giá rẻ, hạ giá, giảm giá vì nó sẽ làm lãng phí thời gian.<br />
<strong>8. Mỗi trang trên Website của bạn nên có tiêu đề khác biệt.</strong> Trừ
phi, nếu website của bạn bị giới hạn về kích thước và độ hiển thị, tốt
nhất không nên sử dụng tiêu đề trang theo cùng một công thức trên toàn
website. Bạn cũng không nên sử dụng cùng một từ khóa ở ngay đầu hoặc gần
ngay đầu tiêu đề trang.<br />
<strong>9. Định dạng, thứ tự và lựa chọn từ cho từ ngữ của tiêu đề nên khác biệt</strong> (ít nhiều) với thẻ miêu tả description hoặc phần tiêu đề đầu trang.<br />
<strong>10. Nếu bạn có thương hiệu mạnh, bạn nên đặt nó ở phần cuối tiêu đề</strong>.
Nếu bạn có một trong những thương hiệu tin cậy hàng đầu trên Internet
(như eBay, Amazone, …) thì bạn nên đặt nó lên phần đầu của tiêu đề.
Thông thường, tiêu đề của trang phải được tập trung vào nội dung của
trang và mục đích của người tìm kiếm hơn là thương hiệu website.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-67147434734507758462012-06-05T22:59:00.005+07:002012-06-05T22:59:48.073+07:00Thiết kế website động là gì? Website tĩnh là gì?<h1 class="title" style="background-color: black; color: red;">
</h1>
<div style="background-color: black; color: red;">
<b><strong>Tổng quát về website động, website tĩnh:</strong></b></div>
<ul style="background-color: black; color: red;">
<li><b>website tĩnh là website chỉ bao gồm các trang website tĩnh và không có cơ sở dữ liệu database đi kèm.<a name='more'></a></b></li>
<li><b>website động là thuật ngữ được dùng để chỉ những website có cơ sở dữ liệu và được hỗ trợ bởi các phần mềm phát triển website.</b></li>
</ul>
<div style="background-color: black; color: red;">
<b><strong>Cụ thể và chi tiết hơn là:</strong></b></div>
<div style="background-color: black; color: red;">
<b><strong>I – website TĨNH</strong></b></div>
<ul style="background-color: black; color: red;">
<li><b>website tĩnh thường được xây dựng bằng các ngôn ngữ HTML, DHTML,…</b></li>
<li><b>website tĩnh thường được dùng để thiết kế các trang website có nội dung ít cần thay đổi và cập nhật.</b></li>
<li><b>website tĩnh là website chỉ bao gồm các trang tĩnh và không có cơ sở dữ liệu database đi kèm.</b></li>
<li><b>website tĩnh thích hợp với cá nhân, tổ chức, doanh nghiệp vừa và nhỏ mới làm quen với môi trường Internet.</b></li>
</ul>
<div style="background-color: black; color: red;">
<b>Trang website tĩnh có các ưu và nhược điểm cơ bản dưới đây.</b></div>
<div style="background-color: black; color: red;">
<b><strong>♦ Ưu điểm cơ bản:</strong></b></div>
<ul style="background-color: black; color: red;">
<li><b><br /></b></li>
<li><b><br /></b></li>
<li><b><br /></b></li>
<li><b><br /></b></li>
</ul>
<div style="background-color: black; color: red;">
<b><strong>♦ Nhược điểm cơ bản:</strong></b></div>
<ul style="background-color: black; color: red;">
<li><b><strong>Khó khăn trong việc thay đổi và cập nhật thông tin: </strong>Muốn
thay đổi và cập nhật nội dung thông tin của trang website tĩnh Bạn cần
phải biết về ngôn ngữ html, sử dụng được các chương trình thiết kế đồ
hoạ và <a href="http://www.thietkewebso.com/" title="thiết kế website">thiết kế website</a> cũng như các chương trình cập nhật file lên server.</b></li>
<li><b><strong>Thông tin không có tính linh hoạt, không thân thiện với người dùng:</strong> Do
nội dung trên trang website tĩnh được thiết kế cố định nên khi nhu cầu
về thông tin của người truy cập tăng cao thì thông tin trên website tĩnh
sẽ không đáp ứng được.</b></li>
<li><b><strong>Khó tích hợp, nâng cấp, mở rộng: </strong>Khi muốn mở rộng, nâng cấp một website tĩnh hầu như là phải làm mới lại website.</b></li>
</ul>
<div style="background-color: black; color: red;">
<b><strong>II – website ĐỘNG</strong></b></div>
<ul style="background-color: black; color: red;">
<li><b><br /></b></li>
<li><b><br /></b></li>
</ul>
<div style="background-color: black; color: red;">
<b>Chẳng hạn ứng dụng cơ sở của bạn có chức năng như một công cụ thương
mại điện tử (một cửa hàng trực tuyến) trưng bày catalog sản phẩm trên
website hay theo dõi kho hàng, khi một mặt hàng được giao, ngay lập tức
những trang có liên quan đến sản phẩm đó phản ánh sự thay đổi này. Những
website cơ sở dữ liệu còn có thể thực hiện những chức năng truyền và xử
lý thông tin giữa doanh nghiệp – doanh nghiệp.</b></div>
<ul style="background-color: black; color: red;">
<li>
<div>
<b>website động thường được phát triển bằng các ngôn ngữ lập trình
tiên tiến như PHP, ASP, ASP.NET, Java, CGI, Perl, và sử dụng các cơ sở
dữ liệu quan hệ mạnh như Access, MySQL, MS SQL, Oracle, DB2.</b></div>
</li>
<li><b><br /></b></li>
<li><b><br /></b></li>
</ul>
<div style="background-color: black; color: red;">
<b>Bạn cũng có thể nhìn nhận vấn đề theo khía cạnh khác: chẳng hạn bạn đã có sẵn những cơ sở dữ liệu như CSDL sản phẩm, nhân sự, <a href="http://www.thietkewebso.com/" target="_blank" title="khách hàng">khách hàng</a>
hay bất kỳ cơ sở dữ liệu nào đó mà bạn muốn đưa thêm giao diện website
vào để người dùng nội bộ hay người dùng Internet đều có thể sử dụng
chương trình chỉ với trình duyệt website của mình.</b></div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-762306316555365596.post-88193413123813157592012-06-05T22:50:00.005+07:002012-06-05T22:50:43.036+07:00Hỗ trợ lập trình HTML, CSS, Javascript, PHP và MySQL<h1 class="title" style="background-color: white; color: blue;">
</h1>
<div style="background-color: white; color: blue;">
<strong>Macromedia Dreamweaver 8 là trình biên soạn HTML một cách
chuyên nghiệp dùng để thiết kế, code và phát triển website cùng các
website và các ứng dụng cho website. </strong></div>
<div style="background-color: white; color: blue;">
<strong></strong></div>
<a name='more'></a><strong>Cho dù bạn có thích thú với công
việc viết mã HTML thủ công hoặc bạn thích làm việc trong môi trường biên
soạn trực quan, Dreamweaver cung cấp cho bạn những công cụ hữu ích để
nâng cao kinh nghiệm <a href="http://www.blogger.com/goog_612991223" title="thiết kế website">thiết kế website</a><a href="http://www.thietkewebso.com/" target="_blank"> Click Vào</a>của bạn.</strong><br />
<div style="background-color: white; color: blue;">
Các tính năng biên soạn trực quan trong Dreamweaver cho phép bạn tạo
nhanh các trang web mà không cần các dòng mã. Bạn có thể xem tất cacr
các thành phần trong website của bạn và kéo chúng trực tiếp từ một panel
dễ sử dụng vào 1 văn bản. Bạn có thể nâng cao sản phẩm của bạn bằng
cách tạo và sửa các ảnh trong Macromedia Fireworks hoặc trong ứng dụng
ảnh khác, rồi sau đó chèn trực tiếp vào Dreamweaver. Dreamweaver cũng
cung cấp những công cụ giúp đơn giản hóa việc chèn Flash vào trang web.</div>
<div style="background-color: white; color: blue;">
Bên cạnh những tính năng kéo và thả giúp xây dựng trang web của bạn,
Dreamweaver còn cung cấp một môi trường viết mã đầy đủ chức năng bao gồm
các công cụ viết mã (như tô màu mã, bổ sung thẻ tag, thanh công cụ mã
và thu bớt mã) và nguyên liệu tham chiếu ngôn ngữ trong Cascading Style
Sheets (CSS), JavaScript, ColdFusion Markup Language (CFML) và các ngôn
ngữ khác. Công nghệ Macromedia Roundtrip HTML nhập các văn bản HTML viết
mã thủ công mà không định dạng lại mã; khi đó bạn có thể định dạng lại
mã với phong cách định dạng của riêng bạn.</div>
<div style="background-color: white; color: blue;">
Dreamweaver cũng cho phép bạn xây dựng các ứng dụng web động dựa theo
dữ liệu sử dụng công nghệ máy chủ như CFML, ASP.NET, ASP, JSP, và PHP.
Nếu sở thích của bạn là làm việc với dữ liệu XML, Dreamweaver cung cấp
những công cụ cho phép bạn dễ dàng tạo các trang XSLT, chèn file XML và
hiển thị dữ liệu XML trên trang web của bạn.</div>
<div style="background-color: white; color: blue;">
Dreamweaver có thể tùy biến hoàn toàn. Bạn có thể tạo cho riêng mình
những đối tượng và yêu cầu, chỉnh sửa shortcut bàn phím và thậm chí viết
mã JavaScript để mở rộng những khả năng của Dreamweaver với những hành
vi mới, những chuyên gia giám định Property mới và những báo cáo site
mới.</div>Unknownnoreply@blogger.com0