admin管理员组文章数量:1130349
I have written a custom plugin for people to sign up to a course. The data is submitted in a front end form and stored in a custom table in the database. There is a "course_completed" column that is a boolean that by default is set to 0 (not checked/false).
Then I have a table that gets the data from the database of the people who have registered to the course. Once the course is over the admin should be able to check who has completed the course and click save. I am struggling to find a way that once the checkbox is ticked for a person, their "completed_course" value is changed to 1 in the database.
Code to display database data in table on the backend:
<tbody class="alternate">
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'crm';
$result = $wpdb->get_results ("SELECT * FROM $table_name");
?>
<?php foreach ($result as $field): ?>
<tr>
<td><?php esc_attr_e( $field->id, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->time, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->first_name, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->last_name, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->email, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->phone, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->postcode, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->city, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->address, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->course, 'wp_admin_style')?></td>
<td><input type="checkbox" name="course_completed" value="1" <?php checked( $field->course_completed, 1 ); ?> /></td>
</tr>
<?php endforeach; ?>
</tbody>
Not sure if I am supposed to be using AJAX, a form inside the table or something else.
I have written a custom plugin for people to sign up to a course. The data is submitted in a front end form and stored in a custom table in the database. There is a "course_completed" column that is a boolean that by default is set to 0 (not checked/false).
Then I have a table that gets the data from the database of the people who have registered to the course. Once the course is over the admin should be able to check who has completed the course and click save. I am struggling to find a way that once the checkbox is ticked for a person, their "completed_course" value is changed to 1 in the database.
Code to display database data in table on the backend:
<tbody class="alternate">
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'crm';
$result = $wpdb->get_results ("SELECT * FROM $table_name");
?>
<?php foreach ($result as $field): ?>
<tr>
<td><?php esc_attr_e( $field->id, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->time, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->first_name, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->last_name, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->email, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->phone, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->postcode, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->city, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->address, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->course, 'wp_admin_style')?></td>
<td><input type="checkbox" name="course_completed" value="1" <?php checked( $field->course_completed, 1 ); ?> /></td>
</tr>
<?php endforeach; ?>
</tbody>
Not sure if I am supposed to be using AJAX, a form inside the table or something else.
Share Improve this question edited May 21, 2017 at 0:26 David Lee 3,9413 gold badges15 silver badges20 bronze badges asked May 20, 2017 at 23:05 lukeliasilukeliasi 1112 bronze badges
1 Answer
Reset to default 1Rough answer to get you started.
Inside the loop, use the row's record number (a field called 'IDnumber', unique, auto) to help name the of a .
The hidden <input> should have an id of something like
<input hidden name='idnumber' value='<?php echo $row[idnumber];?>'>
which will cause the vaue of that input field to be the record number of that record. (The <input> statements should be outside of PHP blocks.)
Use the $_POST values to determine which record to update by using the value of the hidden input item ('idnumber') - which will be the record number you want to update with the other values in the form.
The loop should be surrounded by a <form> block (outside the loop).
I have written a custom plugin for people to sign up to a course. The data is submitted in a front end form and stored in a custom table in the database. There is a "course_completed" column that is a boolean that by default is set to 0 (not checked/false).
Then I have a table that gets the data from the database of the people who have registered to the course. Once the course is over the admin should be able to check who has completed the course and click save. I am struggling to find a way that once the checkbox is ticked for a person, their "completed_course" value is changed to 1 in the database.
Code to display database data in table on the backend:
<tbody class="alternate">
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'crm';
$result = $wpdb->get_results ("SELECT * FROM $table_name");
?>
<?php foreach ($result as $field): ?>
<tr>
<td><?php esc_attr_e( $field->id, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->time, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->first_name, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->last_name, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->email, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->phone, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->postcode, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->city, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->address, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->course, 'wp_admin_style')?></td>
<td><input type="checkbox" name="course_completed" value="1" <?php checked( $field->course_completed, 1 ); ?> /></td>
</tr>
<?php endforeach; ?>
</tbody>
Not sure if I am supposed to be using AJAX, a form inside the table or something else.
I have written a custom plugin for people to sign up to a course. The data is submitted in a front end form and stored in a custom table in the database. There is a "course_completed" column that is a boolean that by default is set to 0 (not checked/false).
Then I have a table that gets the data from the database of the people who have registered to the course. Once the course is over the admin should be able to check who has completed the course and click save. I am struggling to find a way that once the checkbox is ticked for a person, their "completed_course" value is changed to 1 in the database.
Code to display database data in table on the backend:
<tbody class="alternate">
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'crm';
$result = $wpdb->get_results ("SELECT * FROM $table_name");
?>
<?php foreach ($result as $field): ?>
<tr>
<td><?php esc_attr_e( $field->id, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->time, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->first_name, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->last_name, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->email, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->phone, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->postcode, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->city, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->address, 'wp_admin_style')?></td>
<td><?php esc_attr_e( $field->course, 'wp_admin_style')?></td>
<td><input type="checkbox" name="course_completed" value="1" <?php checked( $field->course_completed, 1 ); ?> /></td>
</tr>
<?php endforeach; ?>
</tbody>
Not sure if I am supposed to be using AJAX, a form inside the table or something else.
Share Improve this question edited May 21, 2017 at 0:26 David Lee 3,9413 gold badges15 silver badges20 bronze badges asked May 20, 2017 at 23:05 lukeliasilukeliasi 1112 bronze badges
1 Answer
Reset to default 1Rough answer to get you started.
Inside the loop, use the row's record number (a field called 'IDnumber', unique, auto) to help name the of a .
The hidden <input> should have an id of something like
<input hidden name='idnumber' value='<?php echo $row[idnumber];?>'>
which will cause the vaue of that input field to be the record number of that record. (The <input> statements should be outside of PHP blocks.)
Use the $_POST values to determine which record to update by using the value of the hidden input item ('idnumber') - which will be the record number you want to update with the other values in the form.
The loop should be surrounded by a <form> block (outside the loop).
本文标签: ajaxUpdating a checkbox value to database for specific row in table
版权声明:本文标题:ajax - Updating a checkbox value to database for specific row in table 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749198372a2331376.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论