Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.