TAILIEUCHUNG - PHP and MySQL Web Development - P50

PHP and MySQL Web Development - P50: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | Updating Records in the Database 217 select customerid avg amount from orders group by customerid having avg amount 50 Note that the HAVING clause applies to the query will return the following output ------------ ---------------- customerid avg amount ------------ ---------------- 2 ------------ ---------------- Choosing Which Rows to Return One clause of the SELECT statement that can be particularly useful in Web applications is the LIMIT is used to specify which rows from the output should be returned. It takes two parameters the row number from which to start and the number of rows to return. This query illustrates the use of LIMIT select name from customers limit 2 3 This query can be read as Select name from customers and then return 3 rows starting from row 2 in the output. Note that row numbers are zero indexed that is the first row in the output is row number zero. This is very useful for Web applications such as when the customer is browsing through products in a catalog and we want to show 10 items on each page. Updating Records in the Database In addition to retrieving data from the database we often want to change it. For example we might want to increase the prices of books in the can do this using an UPDATE statement. The usual form of an UPDATE statement is UPDATE tablename SET column1 expression1 column2 expression2 . WHERE condition LIMIT number The basic idea is to update the table called tablename setting each of the columns named to the appropriate can limit an UPDATE to particular rows with a WHERE clause and limit the total number of rows to affect with a LIMIT clause. 218 Chapter 9 Working with Your MySQL Database Let s look at some examples. If we want to increase all the book prices by 10 we can use an UPDATE statement without a WHERE clause update books set price price If on the other hand we want to change a single row say to update a customer s address we can do it like .

TỪ KHÓA LIÊN QUAN
Đã 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.