Đang chuẩn bị liên kết để tải về tài liệu:
PHP and MySQL Web Development - P111

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

PHP and MySQL Web Development - P111: 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. | 522 Chapter 25 Building a Shopping Cart Listing 25.2 Continued do_html_footer The script begins by including book_sc_fns.php the file that includes all the function libraries for this application. After that we must begin a session. This will be required for the shopping cart functionality to work. Every page in the site will use the session. There are some calls to HTML output functions such as do_html_header and do_html_footer both contained in output_fns.php . We also have some code that checks if the user is logged in as an administrator and gives her some different navigation options if she is we ll return to this in the section on the administration functions. The most important part of this script is get categories out of database cat_array get_categories display as links to cat pages display_categories cat_array The functions get_categories and display_categories are in the function libraries book_fns.php and output_fns.php respectively. The function get_ categories returns an array of the categories in the system which we then pass to display_categories . Let s look at the code for get_categories . It is shown in Listing 25.3. Listing 25.3 get_categories Function from book_fns.php Function That Retrieves a Category List from the Database function get_categories query database for a list of categories conn db_connect query select catid catname from categories result @mysql_query query if result return false num_cats @mysql_num_rows result if num_cats 0 return false result db_result_to_array result return result Implementing the Online Catalog 523 As you can see this function connects to the database and retrieves a list of all the category IDs and names.We have written and used a function called db_result_to_array located in db_fns.php. This function is shown in Listing 25.4. It takes a MySQL result identifier and returns a numerically indexed array of rows where each row is an associative array. Listing 25.4 db_result_to_array Function from db_fns.php .

crossorigin="anonymous">
Đã 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.