|
Posted by Gilles Ganault on 01/29/08 18:30
Hello
Out of curiosity, is this an acceptable way to build a small,
all-in-one script to create/update/list/delete records in a table?
This is a bit of pseudo-code (eg. don't know if "switch" exists in
PHP, nor if it trickles down in the absence of "break"), but you get
the idea:
============
<?php
$base = "mydb";
switch $status {
case 'update'
//fetch existing record, and go on to next case
$query = "SELECT ... WHERE ..."
case 'create' || 'update'
//Show form to create/modify an existing record
echo "<form method=post>";
echo "<input type=hidden name=status value=\"save\">";
echo "Name <input type=\"text\" name=\"txtField\"><p>";
echo "<input type=\"submit\" name=\"create\"
value=\"Create\"></p>";
echo "</form>";
case 'create_update'
//Save newly-created record
$query = "INSERT..."
case 'create_save'
//Save modified, existing record
$query = "UPDATE..."
case default
//List records, and include a "Modify/delete" button
$query = "SELECT..."
}
============
Thank you.
Navigation:
[Reply to this message]
|