Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
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ả | 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 identifies 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 lll PHP_ petinfo 1 petName Unicorn .