tailieunhanh - Sams Teach Yourself PHP, MySQL and Apache in 24 Hours phần 8

Nếu bạn xác nhận công việc của bạn trong phần trước bằng cách phát hành các truy vấn MySQL thông qua màn hình hoặc giao diện khác, bạn có thể trở nên mệt mỏi gõ SELECT * FROM . cho mỗi bảng. Trong phần này, bạn sẽ tạo ra các kịch bản hai phần đó cho bạn thấy làm thế nào để lựa chọn và xem các bản ghi trong cơ sở dữ liệu của bạn. | Team LiB Viewing Records If you verified your work in the preceding section by issuing queries through the MySQL monitor or other interface you probably became tired of typing SELECT FROM. for every table. In this section you ll create the two-part script that shows you how to select and view records in your database. Listing shows the select-and-view script called . Listing Script Called for Selecting and Viewing a Record 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 php connect to database conn mysql_connect localhost joeuser somepass or die mysql_error mysql_select_db testDB conn or die mysql_error if _POST op view haven t seen the form so show it display_block h1 Select an Entry h1 get parts of records get_list select id concat_ws l_name f_name as disp from master_name order by l_name f_name get_list_res mysql_query get_list or die mysql_error if mysql_num_rows get_list_res 1 no records display_block . p em Sorry no records to select em else has records so get results and print in a form display_block . form method post action _SERVER PHP_SELF P strong Select a Record to View strong br select name sel_id option value Select One option while recs mysql_fetch_array get_list_res id recs id 30 31 32 33 34 display_name stripslashes recs display_name display_block . option value id display_name option 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 display_block . select input type hidden name op value view p input type submit name submit value View Selected Entry p FORM else if _POST op view check for required fields if _POST sel_id header Location exit get master_info get_master select concat_ws f_name l_name as displa from master_name where id _POST sel_id get_master_res mysql_query get_master display_name stripslashes mysql_result get_master_res 0 display_name display_block h1 Showing Record for display_name h1 get

TỪ KHÓA LIÊN QUAN