Checkbox

Hi,

I have a control form with a checkbox filed on it. The user can select multiple values. How can I update those values using a single query.
The update query code that Scriptcase provides (show below) doesn’t work past the second selected value.

/**
 * Update a record on another table
 */

// SQL statement parameters
$update_table  = 'my_table';      // Table name
$update_where  = "databasefield = {checkboxfield}"; // Where clause
$update_fields = array(   // Field list, add as many as needed
     "field_1 = 'new_value_field_1'",
     "field_2 = 'new_value_field_2'",
 );

// Update record
$update_sql = 'UPDATE ' . $update_table
    . ' SET '   . implode(', ', $update_fields)
    . ' WHERE ' . $update_where;
sc_exec_sql($update_sql);

Any help would mean a lot.

If you have a multiple select then it depends on the way you have defined that field of how the field is returned. In general you bind the field to a varchar of suffiecient length and your data is being stored as ’ option1;option2;option10’ for instance. So if this field is read for display the right checkboxes will be filled then. You can of course explode these to individual fields and insert them as separate records but then you will not be able to redo your screen but perhaps this is not necessary?

In SC I have set the field to checkbox and am using Lookup to populate the values. For example they are:
112233
223232
232334
454545

Now on validate I want to update the table (or rows in that table) that contains these numbers only for the selected values. Suppose it is the first and third value. So those rows would be updated…

I will go over your reply in detail a little later. I think my brain has stopped working :slight_smile:

Got it working! I changed the the equal to in where to IN and set the delimiter to comma(,).