简体   繁体   中英

PHP & MySql create tabulated data grid and save in database

I am working in a project where I have following scenario.

I want to create tabulated form at run time. see image below

在此处输入图片说明

I want a control like where user can drag and drop, provide number of rows and columns, labels of rows and columns and save it in mysql database.

Later other users will fetch this table from database and fill different column values.

Problem:

What will be the database schema for this dynamic data grid?

Is there any jQuery plugin to create such editable grid?

As you mention in the comment at Moshe Shaham 's answer: "Actually i am creating a template system for surveys" . Then:

  1. Make a database table to keeping Survey data.

    servey_id , title , etc.

  2. Make a database table to keeping Question data, linked to the survey_id .

    question_id , survey_id , title , type , order

  3. Make database tables to keeping Answer data, linked to the question_id .

    boolean: answer_id , question_id , value/tinyint(1)

    numeric: answer_id , question_id , value/int(11)

    text: answer_id , question_id , value/varchar(255)

As you see you need multiple tables for Answers , because usually you expecting different data for some questions.

Later you can query and make your tables on-the-fly.

I guess it's the most common way on making such a structure.

Regarding the jQuery part, you can just make the table on-the-fly and then use any kinda libraries or jQuery plug-ins for sorting, formatting, styling, etc.

I think the most straightforward solution will be to simply create a new table in the database for each new table the user creates. unless we are talking about a huge number of tables, i think it's simple and easy to work with, since you can let the users select the data type of the column. doing all the custom table in one huge generic table can turn into a mess...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM