Okay so I invested all that stupid energy into learning Perl and then I turn around and this wiki runs on php. Sigh… So here's my first ”interesting” php script. It's a simple form that writes to itself. The idea would be to create a dynamic page that can manage a flat file database and use buttons (or links) to sort the information dynamically and allow the user to edit the database dynamically.
Zillion of these things on the web. Now I want to do one. I really hope I don't need mysql for this…
Formtest.html is the primary page - though if I do it right, I'm sure I could make sort.php do it all. Basically, it's the zero state form. What the user sees when they first come to the page. It calls sort.php. After that, sort just re-posts to itself.
first the php page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Sort</title> </head> <body> <?php print $_REQUEST["sortit"]; ?> <table border="2"> <form action="sort.php" method="post"> <?php for ($r = 0; $r < 3; $r++) { // print the row marker print "<tr>\n"; for ($c = 0; $c < 3; $c++) { $key = "c" . ($r+1) . ($c+1); // Now print the column markers print "<td><input type=\"text\" size=\"2\" name=\"$key\" "; // Print the field $newVal = $_REQUEST[$key]*2; print "value=\"$newVal\"/>"; // print $key; // now terminate the column markers print "</td>\n"; } // terminate the row markers print "</tr>"; } ?> <tr> <td><input type="submit" name="sortit" value="Sort 1" /></td> <td><input type="submit" name="sortit" value="Sort 2" /></td> <td><input type="submit" name="sortit" value="Sort 3" /></td> </tr> </form> </table> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Test PHP Sort</title> </head> <body> <table width="50%" border="2"> <form action="sort.php" method="post"> <tr> <td><input type="text" name="c11" size="2" value="1" /></td> <td><input type="text" name="c12" size="2" /></td> <td><input type="text" name="c12" size="2" /></td> </tr> <tr> <td><input type="text" name="c21" size="2" /></td> <td><input type="text" name="c22" size="2" /></td> <td><input type="text" name="c23" size="2" /></td> </tr> <tr> <td><input type="text" name="c31" size="2" /></td> <td><input type="text" name="c32" size="2" /></td> <td><input type="text" name="c33" size="2" value="9" /></td> </tr> <tr> <td><input type="submit" name="sortit" value="Sort 1" /></td> <td><input type="submit" name="sortit" value="Sort 2" /></td> <td><input type="submit" name="sortit" value="Sort 3" /></td> </tr> </form> </table> </body> </html>