/    Sign up×
Community /Pin to ProfileBookmark

Best way to build a date editing page

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’]; [/code]

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] notation harder to follow compared to [COLOR=”DarkRed”]“his name is $hisname and always has been.”[/COLOR]

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’].”;”
} [/code]

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)

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@scragarMay 25.2007 — I personaly prefare to stick with $row['x'], but if you wanted to just stick it in the format you have why don't you just use:

[code=php]foreach($row as $blah => $temp){
$$blah = $temp;
};[/code]
Copy linkTweet thisAlerts:
@scaiferwauthorMay 26.2007 — Thank you, that was just the trick.

Rob
×

Success!

Help @scaiferw spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...