PHP and MySQL Web Development - P17

PHP and MySQL Web Development - P17: 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. | Iteration Repeating Actions 47 At the beginning of each iteration the condition is tested. If the condition is false the block will not be executed and the loop will end. The next statement after the loop will then be executed. We can use a while loop to do something more useful such as display the repetitive freight table in Figure . Listing uses a while loop to generate the freight table. Listing Generating Bob s Freight Table with PHP body table border 0 cellpadding 3 tr td bgcolor CCCCCC align center Distance td td bgcolor CCCCCC align center Cost td tr distance 50 while distance 250 echo tr n td align right distance td n echo td align right . distance 10 . td n tr n distance 50 table body html In order to make the HTML generated by our script readable it needs to include new lines and spaces. As already mentioned browsers will ignore this but it is important for human often need to look at the HTML if your output is not what you were seeking. In Listing you will see n inside some of the inside a double-quoted string this character sequence represents a new line character. for and foreach Loops The way that we used the while loops previously is very set a counter to begin with. Before each iteration we tested the counter in a condition. At the end of each iteration we modified the counter. We can write this style of loop in a more compact form using a for loop. The basic structure of a for loop is for expression . condition expression2 expression 48 Chapter 1 PHP Crash Course expression is executed once at the start. Here you will usually set the initial value of a counter. The condition expression is tested before each iteration. If the expression returns false iteration stops. Here you will usually test the counter against a limit. expression2 is executed at the end of each iteration. Here you will usually adjust the value of the counter. expression3 is executed once per iteration. This expression

Không thể tạo bản xem trước, hãy bấm tải xuống
28    19    1    27-03-2023
Đã 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.