PHP & MySQL for Dummies- P6
Số trang: 50
Loại file: pdf
Dung lượng: 0.00 B
Lượt xem: 7
Lượt tải: 0
Xem trước 5 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tham khảo tài liệu php & mysql for dummies- p6, công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
PHP & MySQL for Dummies- P6 Chapter 8: Data In, Data Out 231 The program in Listing 8-4 proceeds as follows: 1. It calls the function getPetsOfType. It passes “horse” in a variable $type containing the type of pet. It also sets up $petInfo to receive the data returned by the function. 2. The function connects to the database and selects the database PetCatalog. 3. The function sends a query to get all the rows with $petType in the petType column. $petType is passed to the function in the function call. The data is stored in a table in a temporary location. The variable $result identi- fies the location of the temporary table. 4. It sets up a counter. $j is a counter that is incremented in each loop. It starts at 1 before the loop. 5. It starts a while loop. The function attempts to get a row from the temporary data table and is successful. If there were no rows to get in the temporary location, the while loop would end. 6. It starts a foreach loop. The loop walks through the row, processing each field. 7. It stores values in a multidimensional array. $array_multi is a multidimensional array. Its first key is a number, which is set by the counter. Because this is the first time through the while loop, the counter — $j — is now equal to 1. All the fields in the row are stored in $array_multi with the column name as the key. (I explain multidimensional arrays in detail in Chapter 7.) 8. It increments the counter. $j is incremented by 1. 9. It reaches the end of the while loop. 10. It returns to the top of the while loop. 11. It repeats Steps 5–10 for every row in the results. 12. It returns $array_multi to the main program. $array_multi contains all the data for all the selected rows. 13. $petInfo receives data from the function. All the data is passed. Figure 8-3 shows the structure of $petInfo after the function has finished executing.Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 232 Part III: PHP Figure 8-3: The struc- ture of the multidimen- sional array $petInfo. 14. The main program sends Pet Descriptions to the browser in an HTML table. The appropriate data is inserted from the $petInfo array. The Web page that results from the program in Listing 8-4 is identical to the Web page shown in Figure 8-2, which is produced by a program that does not use a function. Functions do not produce different output. Any program that you can write that includes a function, you can also write without using a function. Functions just make programming easier. Getting Information from the User Many applications are designed to ask questions that users answer by typing information. Sometimes the information is stored in a database; sometimes the information is used in conditional statements to deliver an individual Web page. Some of the most common application tasks that require users to answer questions are ✓ Online ordering: Customers need to select products and enter shipping and payment information. ✓ Registering: Many sites require users to provide some information before they receive certain benefits, such as access to special informa- tion or downloadable software. ✓ Logging in: Many sites restrict access to their pages. Users must enter an account name and password before they can see the Web pages. ...
Nội dung trích xuất từ tài liệu:
PHP & MySQL for Dummies- P6 Chapter 8: Data In, Data Out 231 The program in Listing 8-4 proceeds as follows: 1. It calls the function getPetsOfType. It passes “horse” in a variable $type containing the type of pet. It also sets up $petInfo to receive the data returned by the function. 2. The function connects to the database and selects the database PetCatalog. 3. The function sends a query to get all the rows with $petType in the petType column. $petType is passed to the function in the function call. The data is stored in a table in a temporary location. The variable $result identi- fies the location of the temporary table. 4. It sets up a counter. $j is a counter that is incremented in each loop. It starts at 1 before the loop. 5. It starts a while loop. The function attempts to get a row from the temporary data table and is successful. If there were no rows to get in the temporary location, the while loop would end. 6. It starts a foreach loop. The loop walks through the row, processing each field. 7. It stores values in a multidimensional array. $array_multi is a multidimensional array. Its first key is a number, which is set by the counter. Because this is the first time through the while loop, the counter — $j — is now equal to 1. All the fields in the row are stored in $array_multi with the column name as the key. (I explain multidimensional arrays in detail in Chapter 7.) 8. It increments the counter. $j is incremented by 1. 9. It reaches the end of the while loop. 10. It returns to the top of the while loop. 11. It repeats Steps 5–10 for every row in the results. 12. It returns $array_multi to the main program. $array_multi contains all the data for all the selected rows. 13. $petInfo receives data from the function. All the data is passed. Figure 8-3 shows the structure of $petInfo after the function has finished executing.Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. 232 Part III: PHP Figure 8-3: The struc- ture of the multidimen- sional array $petInfo. 14. The main program sends Pet Descriptions to the browser in an HTML table. The appropriate data is inserted from the $petInfo array. The Web page that results from the program in Listing 8-4 is identical to the Web page shown in Figure 8-2, which is produced by a program that does not use a function. Functions do not produce different output. Any program that you can write that includes a function, you can also write without using a function. Functions just make programming easier. Getting Information from the User Many applications are designed to ask questions that users answer by typing information. Sometimes the information is stored in a database; sometimes the information is used in conditional statements to deliver an individual Web page. Some of the most common application tasks that require users to answer questions are ✓ Online ordering: Customers need to select products and enter shipping and payment information. ✓ Registering: Many sites require users to provide some information before they receive certain benefits, such as access to special informa- tion or downloadable software. ✓ Logging in: Many sites restrict access to their pages. Users must enter an account name and password before they can see the Web pages. ...
Tìm kiếm theo từ khóa liên quan:
thủ thuật máy tính công nghệ thông tin tin học quản trị mạng computer networkTài liệu liên quan:
-
52 trang 434 1 0
-
24 trang 359 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 320 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 311 0 0 -
74 trang 303 0 0
-
96 trang 299 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 291 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 286 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 277 0 0 -
Tài liệu hướng dẫn sử dụng thư điện tử tài nguyên và môi trường
72 trang 270 0 0