PHP 5/MySQL Programming- P90

PHP 5/MySQL Programming- P90: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 | 423 global SdbConn Soutput process a query just to get field names Squery SELECT FROM StableName Sresult mysql_query Squery SdbConn Soutput . HERE form action method post table border 1 tr th Field th th Value th tr HERE SfieldNum 0 while StheField mysql_fetch_field Sresult SfieldName StheField- name if SfieldNum 0 it s the primary key field. It ll be autoNumber Soutput . HERE tr td SfieldName td td AUTONUMBER input type hidden name SfieldName value null td tr HERE else if preg_match . IDS SfieldName Smatch it s a foreign key reference. Use fieldToList to get a select object for this field Chapter 12 Building a Three-Tiered Data Application SvalList fieldToList match 1 fieldName 0 name Soutput . HERE 424 PHP 5 MySQL Programming for the Absolute Beginner tr td fieldName td td valList td tr HERE else it s an ordinary field. Print a text box output . HERE tr td fieldName td td input type text name fieldName value td tr HERE end if fieldNum end while output . HERE tr td colspan 2 input type hidden name tableName value tableName input type submit value add record td tr table form HERE return output end tToAdd 425 The INSERT statement that this function creates uses NULL as the primary key value because all tables in the system are set to AUTO_INCREMENT. I used the same regular expression trick as in smartRToEdit to recognize foreign key references. If they exist I built a drop-down list with fieldToList to display all possible values for that field and send an appropriate key. Any field not recognized as a primary or foreign key will have an ordinary textbox. Processing an Added Record The tToAdd function sends its results to which reorganizes the data much like . The field names and values are converted to arrays which are passed to the procAdd function. function procAdd tableName fields vals generates INSERT query applies to database global dbConn output query INSERT into tableName VALUES foreach vals as theValue query . .

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.