// restrictions on table design //foreign keys MUST
October 29, 2006 on 12:06 pm | In php | No CommentsHERE; } else if (preg_match( /(.*)ID$/ ?, $col, $match)) { //it s a foreign key reference// get table name (match[1]) //create a listbox based on table name and its name field$valList = fieldToList($match[1],$col, $fieldNum, name ?); $output .= <<
HERE; } else { $output .= <<
HERE; } // end if$fieldNum++; } // end foreach$output .= <<< HERE
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp hosting services
// restrictions on table design //foreign keys MUST
October 29, 2006 on 12:06 pm | In php | No Comments// restrictions on table design //foreign keys MUST be named tableID where table is table name// (because mySQL doesn t recognize foreign key indicators) // I also expect a name field in any table used as a foreign key// (for same reason) global $dbConn; $output = ?; $result = mysql_query($query, $dbConn); $row = mysql_fetch_assoc($result); //get table name from field object$fieldObj = mysql_fetch_field($result, 0); $tableName = $fieldObj->table; $output .= <<< HERE
function rToEdit ($query){ //given a one-record query, creates
October 29, 2006 on 2:17 am | In php | No Commentsfunction rToEdit ($query){ //given a one-record query, creates a form to edit that record//works on any table, but allows direct editing of keys//use smartRToEdit instead if you canglobal $dbConn; $output = ?; $result = mysql_query($query, $dbConn); $row = mysql_fetch_assoc($result); //get table name from field object$fieldObj = mysql_fetch_field($result, 0); $tableName = $fieldObj->table; $output .= <<< HERE
HERE; //update: won t update yet, but set up
October 28, 2006 on 2:13 pm | In php | No Comments
HERE; //update: won t update yet, but set up edit form$output .= <<< HERE
HERE; $output .=
\n\n ?; }// end while//add = INSERT INTO
| $field->name | |||
|---|---|---|---|
| $val |
|
Hint: This post is supported by Gama hrvatski web hosting services $output .= \n ?; //look at each fieldforeach ($rowOctober 28, 2006 on 4:30 am | In php | No Comments$output .= $val |
\n ?; } // end foreach$output .= \n\n ?; }// end while$output .= |
\n ?; return $output; } // end qToTableThe viewQuery.phpprogram calls the qToTable()function, but it could be usedanytime you want an SQL query formatted as an HTML table (which turns out tobe quite often). Building an HTML Table for Editing an SQL TableIf the user has appropriate access, she should be allowed to add, edit, or deleterecords in any table of the database. While qToTable()is suitable for viewing theresults of any SQL query, it does not provide these features. The tToEdit()functionis based on qToTable()with a few differences: tToEdit()does not accept a query, but the name of a table. You cannotedit joined queries directly, only tables, so this limitation is sensible. tToEdit()creates a query that returns all records in the specified table. In addition to printing the table data, tToEdit()adds two forms to eachrecord. One form contains all the data needed by the editRecord.phpprogramto begin the record-editing process. The other form added to each record sends all data necessary for deleting a record and calls the deleteRecord.phpprogram. One more form at the bottom of the HTML table allows the user to add a recordto this table. This form contains information that the addRecord.phpprogramneeds. function tToEdit($tableName){ //given a table name, generates HTML table including//add, delete and edit buttonsglobal $dbConn; 410PHP5/MySQLProgrammingfortheAbsoluteBeginner
Hint: This post is supported by Gama hrvatski web hosting services
The mainButton()function uses the value of $mainProgramto build
October 27, 2006 on 6:14 pm | In php | No Comments$output = ?; $result = mysql_query($query, $dbConn); //print dbConn is $dbConn
?; //print result is $result
?; while ($row = mysql_fetch_assoc($result)){ foreach ($row as $col=>$val){ $output .= $col: $val
\n ?; } // end foreach$output .=
\n ? ; } // end whilereturn $output; } // end qToListBuilding an HTML Table from a QueryThe qToTable()function is a little more powerful than qToList(). It can build an HTML table from any valid SQL SELECTstatement. The code uses themysql_fetch_field()function to determine field names from the query result. Italso steps through each row of the result, printing an HTML row correspondingto the record. function qToTable($query){ //given a query, automatically creates an HTML table outputglobal $dbConn; $output = ?; $result = mysql_query($query, $dbConn); $output .=
| $field->name |
|---|