Editable Grid

Hello Everyone,

i have a question regarding de editable grid form, i’m using it because it gives the best visual results for what i’m trying to achieve. the form is made to display a set of questions that i have on a database. and the answers must be saved on another table. so i have something like this

Question_field Answer_field
QUESTION 1 ANSWER1
QUESTION 2 ANSWER2
QUESTION 3 ANSWER3

Question_field is a text field set to label so user cant change it and the values it show are the questions the users needs to answer.

Answer_field was created since it’s not part of the Question table and it’s a select field

I created a php button and instruct it to insert the values of both question_field and answer_field to another table with the following code:

$insert_table = ‘tb_eval_prof’; // Table name
$insert_fields = array( // Field list, add as many as nee
‘QUESTION’ => “{question_field}”,
‘ANSWER’ => “{answer_field}”
);

// Insert record
$insert_sql = ‘INSERT INTO ’ . $insert_table
. ’ (’ . implode(’, ‘, array_keys($insert_fields)) . ‘)’
. ’ VALUES (’ . implode(’, ', array_values($insert_fields)) . ‘)’;
sc_exec_sql($insert_sql);

the problem i have is that when i execute this SQL, both fields show no value, and i think is that i need to instruct wich row of the field i want to insert on each row of the database but i dont know how to do it.

:frowning:

Re: Editable Grid

anyone? :frowning:

Re: Editable Grid

If you want to loop through the records in the form, I’m afraid the onlyway to do this is with javascript. No experience with that.

Apart from your database structure, what are you trying to achieve?

In the form you display several different questions, and each question has an answer field (type select), with fixed opions from a lookup table?
Does each question have the same possible set of answers?

Re: Editable Grid

What i’m looking for is to create a simple evaluation form. each question will always have the same options on the select field which are (excellent, very good, good, regular, mediocre).

the answers_table has the following structure

id | Date | code_evaluator | code_eval | code_question | code_answer

where the columns:
id is Auto incremented by the database
code_evaluator is the id of the person filling the form. the value is been acquired using a global variable created on the control form
code_eval is a random code generated when loading the form and is ussed to create a unique identifier for the form being filled.
code_question will store the numeric code for the question being answered
code_answer column will store the value of the answer

the table should look like this when data is entered

id | Date | code_evaluator | code_eval | code_question | code_answer
1 |04/08/2011 20:00:00| 1 | 3AMSGGGB | 1 | 5
2 |04/08/2011 20:00:00| 1 | 3AMSGGGB | 2 | 1
3 |04/08/2011 20:00:00| 1 | 3AMSGGGB | 3 | 2

Re: Editable Grid

I would do it this way, not very different from what you wrote:

create a questions table -> stores the unique questions to be asked
create a lookup table (holding values “Excellent”, “Very good” …)
create a evaluation table -> holds answers to the questions (user_id, question_id, answer)

Insert questions in questions table.
Insert answer options in lookup table.
For each user who will participate in the evaluation create records in evaluation table.

Create a editable grid on table evaluation that loads only the records from evaluation table for the current user_id.
Field “answer” is of type select, and in edition lookup, load the values from lookup table.
Field “question_id” will have Grid lookup SQL command to actually display the question itself.

Hope this helps.

Re: Editable Grid

you mean to first insert the user and question id to the evaluation table and then load a editable grid using those records?

something like this:
user logs on and application records its ID
user selects type of evaluation and hits button

process from button inserts user ID and question ID to evaluation table based on a SQL statement that will filter only those questions that the user has access to based on its ID and type selected.

at end of process editable grid is loaded based on the records created by that user ID and unique key is created for that specific form

also it could be to create a temp_evaluation table with the same structure as master_evaluation table to insert the records and it will only be saved on master evaluation table if the user selects a “save” button, if he/she closes the evaluation form without saving it the temp table will disapear and no garbage records are saved into the master evaluation table.

Re: Editable Grid

I just found a problem with what i just posted, how can i create on site an editable grid form based on a temp table?

Re: Editable Grid

I took your advice and created a control form that will have a button that when pressed will insert the rows on the answer table and then (hopefully) open a form for the user to fill the answers. i have just made the form using editable grid, but i’d like to know if there’s a way to make a button on that form that updates all rows at the same time instead of having to update each row individually.

Re: Editable Grid

Create the rows for the user using a SQL insert statement. Then, open de editable grid where you select the rows just inserted.

Multiple row update/save functionality is unfortunately not available in editable grid.

Re: Editable Grid

Thanks Freezer i just did that and the form is working. however i have an issue, when an user clicks on an evaluation button, the rows get inserted and the evaluation loads; if the user then closes the evaluation without saving anything, i get blank rows that i later will have to delete to save space.
That’s why i thought about using a temp table for the evaluation that later when the evaluation is saved will insert the rows on the main answer table. when the evaluation is finished the temp table drops itself automatically.

The thing is that i cant find a way to do it this way since i cannot create a form from a table that will only exist when a user clicks on a button.

Re: Editable Grid

How many questions and how many users do you expect to fill the evaluation?

When a user clicks the evaluation button, you may expect him/her to complete the evalutation. I guess the number of users that does not, will only represent a small percentage.

If you really worry abuot the number of empty records, you could make a batchjob that deletes the empty records every night or week.

Re: Editable Grid

since this evaluation is meant to be filled by students, parents, teachers, and school administrators, the number of users expected to fill the evaluation forms are from 1000-2000 depending on the school.

The questions for each evaluation will vary depending on the type of evaluation selected, each user depending on its rank will have access to one or more types of evaluation for ex: a student can evaluate his teacher, and his school. a teacher can evaluate his coordinator, his director and the school and so on.

Re: Editable Grid

a batchjob that deletes the empty records every night or week, is that acceptable?

Re: Editable Grid

yeah, im already working with mysql scheduled procedures to get that done. what i’m trying to figure out now is how can i make a button that will save all records at once using javascript. i can’t have a person saving the answers to each question on a 50 question form.