Jump to content

Iterating


zero_ZX

Recommended Posts

Hi,

I have a class that loops through a mysql table and then auto generates a form based on the table. It can ignore fields if there should be a need of that.

Any way I would like to label the different inputs, provide descriptions etc, and would like to know an approach to this.

What would you do in this case? I have a matching table containing settings where i could put a field and then it could contain a serialized array with the info, but not sure if there's a better alternative, please let me know :)

Link to comment
https://forums.phpfreaks.com/topic/263536-iterating/
Share on other sites

The simplest way to do this is is with a single table:

 

CREATE TABLE inputs (

    `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

    `name` VARCHAR(255) NOT NULL,

    `type` ENUM('text', 'password', 'textarea', 'select', 'multiselect', 'checkbox', 'checklist', 'radiolist') NOT NULL DEFAULT 'text',

    `label` VARCHAR(255) NULL,

    `options` TEXT NULL

);

 

Use `options` to store option values for "select", "multiselect", "checklist", and "radiolist" types.

 

You can comma-delimit the field, then explode(",", $data['options']) in your php to retrieve an array of values.

 

Link to comment
https://forums.phpfreaks.com/topic/263536-iterating/#findComment-1350608
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.