Page 1 of 1

[SOLVED] Database Field Naming and Form Creation

Posted: Tue Jul 04, 2006 9:27 am
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.

Posted: Tue Jul 04, 2006 9:31 am
by feyd

Posted: Tue Jul 04, 2006 9:48 am
by jayshields
That looks dandy. Counldn't find that myself! Didn't know what to search for!

Posted: Wed Jul 05, 2006 8:51 am
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!