[SOLVED] Database Field Naming and Form Creation

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

[SOLVED] Database Field Naming and Form Creation

Post by jayshields »

Couldn't think of a good topic title, sorry.

Anyway, if I create a table called 'blah' and it has fields named dish_size, mat, mount.

Can I define constants like so:

Code: Select all

define('dish_size', 'Size: ');
define('mat', 'Material: ');
define('mount', 'Mounting Bracket: ');
Then when I am creating an admin form to add rows to my table, I can simply pull all the fields from the table and change the "scruffy" field name for a nicely written one on the fly - that way I don't have to hardcode it.

I know that I would simply need to do something like:

Code: Select all

echo mat . '<input type="text" ... />';
but I don't want to do that because it would obviously require me to go through them all and it would be defeating the object, I just want to loop through all the table fields and create a form entry box for each one with the proper field name being put in for each field, but how can I get PHP to recognise I want a variables value exchanging for a constants value.

So if

Code: Select all

$field[0] = 'mat';
echo $field[0]; //would output "Material: ", instead of simply "mat"
That's what I can't get my head around.

I hope you understand what I mean!

Cheers.
Last edited by jayshields on Tue Jul 04, 2006 9:49 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

That looks dandy. Counldn't find that myself! Didn't know what to search for!
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Wow, I'm so glad I looked into this.

It's for an admin panel, where I need forms to add to 4 different tables.

I have just made a script which shows a nice form for any of the tables in 85 lines!
Post Reply