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

CONNECTING TO MYSQL WITH PHP AND SQL foreach ($conn-query($sql) as $row) { // do something with the current record } In the case of the images table, $row contains $row['image_id'], $row['filename'], and $row['caption']. Each element is named after the corresponding column in the table. PHP Solution 11-4: Displaying the images table using MySQLi This PHP solution shows how to loop through a MySQLi_Result object to display the results of a SELECT query. Continue using the file from PHP Solution 11-2. 1. Add the following table to the main body of (the PHP code that displays the result set is highlighted in bold):. | CONNECTING TO MYSQL WITH PHP AND SQL foreach conn- query sql as row do something with the current record In the case of the images table row contains row image_id row filename and row caption . Each element is named after the corresponding column in the table. PHP Solution 11-4 Displaying the images table using MySQLi This PHP solution shows how to loop through a MySQLi_Result object to display the results of a SELECT query. Continue using the file from PHP Solution 11-2. 1. Add the following table to the main body of the PHP code that displays the result set is highlighted in bold table tr th image_id th th filename th th caption th tr php while row result- fetch_assoc tr td php echo row image_id td td php echo row filename td td php echo row caption td tr php table The while loop iterates through the database result using the fetch_assoc method to extract each record into row. Each element of row is displayed in a table cell. The loop continues until fetch_assoc comes to the end of the result set. 2. Save and view it in a browser. You should see the contents of the images table displayed as shown in the following screenshot 311 CHAPTER 11 Download from Wow eBook You can compare your code if necessary with mysql_02 .php in the ch11 folder. PHP Solution 11-5 Displaying the images table using PDO Instead of a while loop with fetch_assoc PDO uses the query method in a foreach loop. Continue working with the same file as in PHP Solution 11-3. 1. Insert the following table in the body of the PHP code that displays the result set is displayed in bold table tr th image_id th th filename th th caption th tr php foreach conn- query getDetails as row tr td php echo row image_id td td php echo row filename td td php echo row caption td tr php table 2. Save the page and view it in a browser. It should look like the screenshot in PHP Solution 11- 4. You can compare your code against pdo_02. php in the ch11 folder. 312 .

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.