PHP 5/MySQL Programming- P17

PHP 5/MySQL Programming- P17:computer programming has often been seen as a difficult and arcane skill. Programming languages are difficult and complicated, out of the typical person’s reach. However, the advent of the World Wide Web has changed that to some extent. It’s reasonably easy to build and post a Web page for the entire world to see. The language of the Web is reasonably simple, and numerous applications are available to assist in the preparation of static pages | 58 PHP 5 MySQL Programming for the Absolute Beginner The rand function generates a random number between 1 and 6 inclusive and stores the resulting value in the roll variable. The rand function expects two parameters The first value is the lowest number and the second value represents the highest number. Since I want to replicate an ordinary six-sided die I told the rand function to return a value between 1 and 6. Since I knew that rand would return a value I assigned that resulting value to the variable roll. By the time the following line has finished executing the roll variable has a random value in it roll rand 1 6 The lowest possible value is 1 the highest possible value is 6 and the value will not have a decimal part. In other words it will never be . tR If you re coming from another programming language you might be surprised at the _ way random numbers are generated in PHP. Most languages allow you to create a - random floating-point value between 0 and 1 and then requires you to transform that value to whatever range you wish. PHP allows in fact requires you to create random integers within a range which is usually what you want anyway. If you really want a value between 0 and 1 you can generate a random number between 0 and 1000 and then divide that value by 1000. Printing a Corresponding Image Notice the sneaky way I used variable interpolation in the preceding code. I carefully named my first image the second and so on. When I was ready to print an image to the screen I used an ordinary HTML image tag with the source set to die . If roll is 3 the image shows . Variable interpolation can be a wonderful trick if you know how the filenames are structured. You might recall from chapter 2 Using Variables and Input that interpolation is the technique that allows you to embed a variable in a quoted string by simply using its name. Using the if Statement to Control Program Flo One of the most interesting things computers do

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.