TAILIEUCHUNG - PHP for Absolute Beginners PHẦN 5

Một tính năng tuyệt vời được cung cấp bởi PHP là khả năng để tải một kịch bản từ một tập tin bên ngoài, điều này làm cho nó dễ dàng hơn nhiều để tổ chức mã của bạn trong các dự án lớn hơn. PHP cung cấp bốn xây dựng bạn có thể sử dụng để tải một kịch bản bên ngoài: bao gồm, include_once, yêu cầu, và require_once. PHP hướng dẫn khuyến cáo rằng | CHAPTER 5 BUILDING THE ENTRY MANAGER if is_array e fulldisp 1 e array title No Entries Yet entry a href Post an entry a Return loaded data You can now run your function safely without an error so long as no entry ID is supplied. Next you need to modify the script so it retrieves an entry if an ID is supplied. This code needs to use the supplied ID in a query to retrieve the associated entry title and entry fields. As before you store the returned data in an array called e. Add the code in bold to php function retrieveEntries db id NULL If an entry ID was supplied load the associated entry if isset id sql SELECT title entry FROM entries WHERE id LIMIT 1 stmt db- prepare sql stmt- execute array _GET id Save the returned entry array e stmt- fetch Set the fulldisp flag for a single entry fulldisp 1 Download at 145 CHAPTER 5 BUILDING THE ENTRY MANAGER If no entry ID was supplied load all entry titles else sql SELECT id title FROM entries ORDER BY created DESC Loop through returned results and store as an array foreach db- query sql as row e array id row id title row title Set the fulldisp flag for multiple entries fulldisp 0 If no entries were returned display a default message and set the fulldisp flag to display a single entry if is_array e fulldisp 1 e array title No Entries Yet entry a href Post an entry a Return loaded data At this point your function has two variables e and fulldisp. Both variables must be returned from the function for further processing however a function can return only one value so you need to somehow combine these variables into a single variable. You do this using a function called array_push which adds a value to the end of an array. Using this function you can add the value of fulldisp to the end of e and return e. 146 Download at CHAPTER 5 BUILDING THE ENTRY MANAGER You can accomplish this by adding the code in bold to php function retrieveEntries db id NULL

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.