[SOLVED] reference to an array from a DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
turbo2ltr
Forum Commoner
Posts: 29
Joined: Sun Jul 18, 2004 4:08 pm

reference to an array from a DB

Post by turbo2ltr »

Hello all!
I'm creating a parametric search page that has groups of checkboxes on it. All the info is served from a DB. I have a "fieldtable" that has a list of column names in the "maintable". The ENUM values for each column are picked out of the Main Table and a checkbox is made for each.
So something like

Some table field:
CHK Enum 1
CHK Enum 2

This repeats for all the main table fields listed in fieldtable. This makes for very short code that creates a large page.

The name that I want to give the return value is also puled from the "fieldtable". The data is posted back using "someval[]" syntax in the checkbox code so it's posted back as an array.

$name = $sqlresult[fields_returnval];
$name= $name."["."]";
<INPUT TYPE=CHECKBOX name=\"$name\" value=\"$option\">$option

Now to my question. I got up to the point where I want to start parsing the post data. In the "fieldtable" I have the name of the variable so I thought I'd just loop through again and pull all the data out of the returned arrays. But I couldn't figure out if there is any way to take a text field and somehow convert it to an array name.

Generated HTML:
<INPUT TYPE=CHECKBOX name="color[]" value=red>red
<INPUT TYPE=CHECKBOX name="color[]" value=blue>blue

Then when its posted,there will be an array $color[] that will contain "red" and/or "blue"..or nothing.

In my fieldtable, I can pull "color" out of it, but can I make this somehow reference the actual $color[] array?

Sorry this is so cofusing...I hope someone understands what I'm trying to do...

Thanks!
Mike
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$color = (isset($_POST['color']) ? &$_POST['color'] : array() );
:?:
turbo2ltr
Forum Commoner
Posts: 29
Joined: Sun Jul 18, 2004 4:08 pm

Post by turbo2ltr »

Wow, I'm dumb. That was too easy. I never use the $_POST gloabals I always just reference them directly. I never understood the need for the $_POST if you can get to them directly...now I do..That worked great.
Thanks!
Mike
Post Reply