×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Saving table data to MySQL

Saving table data to MySQL

Saving table data to MySQL

(OP)
I have just about finished my first ever PHP project (a Sports Club Management System converted from a Del[phi app) and I am left with one thing to complete. The attendance register. More specifically saving the data back to the MySQL table. Everything else works fine

Basically the attendance table has the following structure
Member_ID
Session_ID
Attend

The latter field is a string in the format "1,0,1,1,1,0,0,1,1,1,0,0,1" where each 0 or 1 signifies attendance at each of the 13 sessions available in the term.

Each session will have no more than 25 attendees.

The data is assembled into a table, within a form, with each table row consisting of 15 <td>s. The first is an indicator (used to show expanded member data), the second the members name, and the remainder the 13 attendance indicators as checkboxes (1= Attended, 0 = not attended)

The code used to build the table is:

CODE --> PHP

<?php
                            while($g_fetch = $a_query->fetch_array()) {
                                $checked = array();
                                $memid = $g_fetch['mem_id'];
                                $name = $g_fetch['firstname'].' '.$g_fetch['lastname'];
                                $attendences = explode(",",$g_fetch['attend']);
                                for ($x = 0; $x <= 12; $x++) {if ($attendences[$x]!="0") {$checked[$x] = 'checked = "checked"';} else { $checked[$x] = '';}}
                                
                                /* Now display table data rows */
                                echo '<tbody><tr class="parent">';  
                                echo '<td><i class="fa fa-chevron-down"></i></td>';
                                echo '<td name="'.$memid.'">'.$name.'</td>';
                                for ($y = 0; $y <= 12; $y++) { 
                                  if ($y <> $NoWeeks){ $dis = ' disabled'; } else {$dis = '';}
                                  echo '<td align="center"><input type="checkbox"  value = "1" '.$checked[$y].'" "'.$dis.'></td>';
                                  }	
                                echo '</tr>';
                                echo '<tr class="cchild">';
                                echo '<td colspan="5">';   
                                echo "Parent Name: <b>".$g_fetch['parent_name']."</b><br />";
                                echo "Parent Tel: <b>".$g_fetch['parent_tel']."</b><br />";
                                echo "Emergency 1: <b>".$g_fetch['emergency1']."</b><br />";
                                echo "Emergency 2: <b>".$g_fetch['emergency2']."</b><br />";
                                echo '</td>';
                                echo '<td colspan="5" >';   
                                echo '</td>';   
                                echo '<td colspan="5" >';
                                echo '</td>';   
                                echo '</tr></tbody>'; 
                                unset($checked);
                                unset($attendences);
                            }	 
                            ?>
                       </table> 

This works ok, but am having trouble saving the data back to the table after clicking on the form Save button (set up as a POST)
I have read that I need to set up the checkboxes as an array and assign a different value to each.
I assume this means for each checkbox setting it to something like name="attend[".$y."]"
Now I am stuck - I assume that for each row I can use the second <td>s name to find the record to update, and that I can assemble the attend[] elements to build the attendance string.
However I cannot seem to get the looping through the rows to get the various elements to work.
Any help gratefully received.
Many thanks

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close