Practical PHP and MySQLBuilding Eight Dynamic Web Applications phần 3

để thêm các tính năng như một mô tả của danh mục, biểu tượng hạng mục, các định nghĩa dịch, và nhiều hơn nữa. Một lý do lớn để giải nén dữ liệu vào các bảng riêng biệt là dễ sử dụng. Nếu bạn có một bảng duy nhất với một số lượng lớn các lĩnh vực, có vẻ rất phức tạp và khó khăn để đối phó với. | CHAPTER 4 Building a Weblog 91 The next line is the SQL query. This query inserts the data into the database with an INSERT statement. A typical INSERT statement looks like this INSERT INTO table field1 field2 VALUES data for field 1 data for field 2 When you construct the SQL statement in your sql variable you concatenate the various variables from the form that are accessed with _POST. To demonstrate how this fits together imagine that you are adding a comment to the blog entry with 2 as an ID at 2 30 . on August 10 2005. Assume that the user types Bob Smith as the name and I really like your blog. Cool stuff as the comment. Table 4-5 demonstrates how the query is built. TABLE 4-5 The sql variable is built up into an INSERT statement Concatenated Element SQL Statement INSERT INTO comments blog_id dateposted name comment VALUES INSERT INTO comments blog_id dateposted name comment VALUES validentry INSERT INTO comments blog_id dateposted name comment VALUES 2 NOW INSERT INTO comments blog_id dateposted name comment VALUES 2 2005-08-10 14 30 00 _POST name INSERT INTO comments blog_id dateposted name comment VALUES 2 2005-08-10 Bob Smith . INSERT INTO comments blog_id dateposted name comment VALUES 2 2005-08-10 Bob Smith _POST comment INSERT INTO comments blog_id dateposted name comment VALUES 2 2005-08-10 Bob Smith I really like your blog. Cool stuff INSERT INTO comments blog_id dateposted name comment VALUES 2 2005-08-10 Bob Smith I really like your blog. Cool stuff 92 Practical PHP and MySQL The left column lists each part of the code the right column shows how the content of the page is built up in the query. As you read the table remember that numbers don t need single quotes around them such as the number in validentry but strings letters and sentences do. One part of the code that will be new to you is NOW . This is a special MySQL function that provides the current date and time and you will use NOW to automatically fill the dateposted field. NOTE Built-In

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.