TAILIEUCHUNG - Beginning PHP6, Apache, MySQL Web Development- P3
Beginning PHP6, Apache, MySQL Web Development- P3:Welcome to Beginning PHP6, Apache, MySQL Web Development , your new trusty resource for assistance in creating your own dynamic web sites. There are a lot of technologies available that can be used to deliver great web sites, and we ’ re glad you chose the Apache/MySQL/PHP (sometimes referred to simply as AMP) approach. You may or may not have had a taste of these three components in the past, but either way we ’ re confident that you will be impressed with the power that lies within them | Chapter 2 Creating PHP Pages Using PHP6 How It Works By defining the constant known as FAVMOVIE you have set the value as The Life of Brian which can be recalled and displayed later on. Although this constant can t be changed or reset throughout your script it is available for use by any part of your script. Overview of Variables Unlike constants variables are obviously meant to be variable they are meant to change or be changed at some point in your program. Variables do not need to be defined or declared and can simply be assigned when needed. They act as a container that stores information for later use in your scripts and the contents of them can be changed. Variables are denoted with a dollar sign and are case-sensitive in other words dateEntered and DateEntered are treated as different variables . The first letter of the variable name must be an underscore or letter and cannot be a number. Try It Out Using Variables In this exercise you ll add variables to your existing script. 1. Open your text editor and make the following changes to your file noted in highlighted lines html head title My Movie Site title head body php definef FAVMOVIE The Life of Brian echo My favorite movie is echo FAVMOVIE echo br movierate 5 echo My movie rating for this movie is echo movierate body html 2. Save the changes and access the file in your browser. Your screen should now look like the one in Figure 2-5. 31 Part I Movie Review Web Site Figure 2-5 How It Works The value 5 is assigned to the variable movierate. Numbers do not need to be quoted as strings do. In fact the following would cause PHP to see the value of movierate as a string containing the character 5 movierate 5 Keeping this value as an integer makes it much easier to perform mathematical calculations on it later on such as giving the viewer the average movie rate. For example php bobsmovierate 5 joesmovierate 7 grahamsmovierate 2 zabbysmovierate 1 avgmovierate bobsmovierate joesmovierate .
đang nạp các trang xem trước