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

PULLING DATA FROM MULTIPLE TABLES " The first tag is hard-coded with the label Select image, and its value is set to an empty string. The remaining tags are populated by a while loop that extracts each record to an array called $row. A conditional statement checks whether the current image_id is the same as the one already stored in the articles table. If it is, selected is inserted into the tag so that it displays the correct value in the drop-down menu. Make sure you don t omit the third character in the. | PULLING DATA FROM MULTIPLE TABLES option value php echo row image_id php if row image_id image_id echo selected php echo row filename option php select p The first option tag is hard-coded with the label Select image and its value is set to an empty string. The remaining option tags are populated by a while loop that extracts each record to an array called row. A conditional statement checks whether the current image_id is the same as the one already stored in the articles table. If it is selected is inserted into the option tag so that it displays the correct value in the drop-down menu. Make sure you don t omit the third character in the following line php echo row filename option It s the closing angle bracket of the option tag sandwiched between two PHP tags. 3. Save the page and load it into a browser. You should be automatically redirected to . Select one of the EDIT links and make sure that your page looks like Figure 15-4. Check the browser source code view to verify that the value attributes of the option tags contain the primary key of each image. 4. The final stage is to add the image_id to the UPDATE query. Because some blog entries might not be associated with an image you need to create alternative prepared statements like this if form has been submitted update record if isset _POST update prepare update query if empty _POST image_id sql UPDATE blog SET image_id title article WHERE article_id stmt- prepare sql stmt- bind_param issi _POST image_id _POST title _POST article _POST article_id 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 421 CHAPTER 15 Download from Wow eBook If _POST image_id has a value you add it to the SQL as the first parameter with a placeholder question mark. Since it must be an integer you add i to the beginning of the first argument of bind_param . .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
38    91    2    29-06-2024
Đã 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.