TAILIEUCHUNG - Giải pháp thiết kế web động với PHP - p 48

MANAGING MULTIPLE DATABASE TABLES } else { $sql = 'UPDATE blog SET image_id = NULL, title = ?, article = ? WHERE article_id = ?'; $stmt-prepare($sql); $stmt-bind_param('ssi', $_POST['title'], $_POST['article'], $_POST['article_id']); } $stmt-execute(); $done = $stmt-affected_rows; } The last two lines of this code block execute the prepared statement that updates the record in the blog table, and then assign the number of affected rows to $done. If you update a record, the affected_rows property is 1, which is treated as true. However, if you don t make any changes to the record, affected_rows is 0, which is treated as false. If. | MANAGING MULTIPLE DATABASE TABLES else sql UPDATE blog SET image_id NULL title article WHERE article_id stmt- prepare sql stmt- bind_param ssi _POST title _POST article _POST article_id stmt- execute done stmt- affected_rows The last two lines of this code block execute the prepared statement that updates the record in the blog table and then assign the number of affected rows to done. If you update a record the affected_rows property is 1 which is treated as true. However if you don t make any changes to the record affected_rows is 0 which is treated as false. If you update only the categories associated with a record without changing the record itself done is interpreted as false and you won t be returned to . Delete the following line done stmt- affected_rows 6. Assign the return value of stmt- execute to done like this done stmt- execute The execute method returns true if the prepared statement is executed successfully even if it doesn t result in any changes to the record. 7. Immediately after the line you have just edited insert the code to delete existing values in the cross reference table and to insert the newly selected values like this done stmt- execute delete existing values in the cross-reference table sql DELETE FROM article2cat WHERE article_id stmt- prepare sql stmt- bind_param i _POST article_id stmt- execute insert the new values in articles2cat if isset _POST category is_numeric _POST article_id article_id int _POST article_id foreach _POST category as cat_id values article id . int cat id . if values sql INSERT INTO article2cat article_id cat_id VALUES . implode values if conn- query sql catError conn- error 451 CHAPTER 16 Download from Wow eBook This code needs little explanation. The DELETE query removes all entries in the cross-reference table that match article_id. The remaining code inserts the values selected in the update form. It s identical to the code in step 4 of PHP Solution 16-4. The key thing .

TỪ KHÓA LIÊN QUAN
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.