I can’t help but feel that I’m doing this the hard way.
Every time I build a page with a date editing form, I need to read the form from the db, then painfully build a long list of variables, pulling each attribute I want from the database and creating a variable, such as;
[code=php]$address=$row[‘address’];
$city=$row[‘city’];
$provstate=$row[‘provstate’];
$postal=$row[‘postal’];
I suppose I could just use the $row[‘attribute’] directly in my form code to populate the form with the pre-existing data, but I find the [COLOR=”DarkRed”]“His name is “.$row[‘hisname’].” and always has been.”[COLOR=”DarkRed”]“his name is $hisname and always has been.”
My other idea, Plan B, is to do something like this (haven’t tried it yet, code probably doesn’t work as is), which seems easier to build and easier to modify if I add or drop fields to work with;
[code=php]
$fieldlist = array (“address”, “city”, “provstate”, “postal”);
foreach ($fieldlist as $temp) {
$$temp = $row[‘$temp’].”;”
}
Of course I can use the same $fieldlist array when building the insert statement.
Does plan B make more sense? Or am I being dense and overlooking a much more reasonable approach?
What do most people do?
(using PHP 5.x and MySQL 5.x)