|
Posted by The Natural Philosopher on 01/29/08 19:23
Gilles Ganault wrote:
> 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?
>
Whatever turns you on.
Ive got lots of code like this, generally done custom foir te form,
using if then els if type constructs, and a hiddne variable called
'update' which takes values NULL, 'yes', and 'new'
The display is the same whether I am creating new or updating tho. The
only difference is the variables that go in the input boxes are blank if
its 'new'
The difference is how teh php pricess teh DATABASE, not e screen.
If its caled as a result of a frm submit, I tet for a new recird, or
updating old. Thats goes into one of three possible states. Update
existing, create new, or do nothing.
Then in all cases bar record ID=0/NULL the database is READ to fill in
the form.
> 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]
|