With the help of Court Shrock, who answered by original request for help, I
have managed to create an array of form data that can be fed to a mySQL
UPDATE query.  In case anyone else needs to do this, here's the solution I
reached.

The existing data is read from the database and placed in cells that look
like this sample:

<td align=\"center\">
  <input type=\"text\" name=\"log[$week_no][classroom]\"
value=\"$classroom\" size=\"2\" maxlength=\"4\">
  </td>

The trick here is the array log[][].  Data from the columns is stored in
rows identified by week_no.

The UPDATE sql looks like this:

#loop through the log[][] array;
 foreach($log as $week_no => $data)
 {
 $classroom = $data[classroom];
 $homework = $data[homework];
 $library = $data[library];
 $fieldtrip = $data[fieldtrip];
 $pta = $data[pta];
 $mast = $data[mast];
 $meetings = $data[meetings];
 $other = $data[other];

 $sql = "UPDATE parent_log
  SET
  classroom = \"$classroom\",
  homework = \"$homework\",
  library = \"$library\",
  fieldtrip = \"$fieldtrip\",
  pta = \"$pta\",
  mast = \"$mast\",
  meetings = \"$meetings\",
  other = \"$other\"
  WHERE parent_id = \"$parent_id\"
  AND student_id = \"$student_id\"
  AND week_no = \"$week_no\"
 "; # end create sql query

The foreach format and figuring out to extract the data in preparation for
the UPDATE command caused me the most trouble.  The demo site mentioned in
the original message has been modified to incorporate the one-button update
feature for those who would like to see how this works.

John Hughes




----- Original Message -----
From: "John Hughes, Jomari Works" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, March 11, 2002 10:42 PM
Subject: [PHP-DB] Creating an array of mySQL results with PHP


> I am working on the creation of Web-based database where parents log the
> hours they spend participating in school activities. (The school requires
> that parents spend two hours each week.)
>
> I have a prototype demonstration site at http://fuzzheads.org/demo
>
> As currently constructed, the parent log database contains a record for
each
> week (there are a total of 39 in the school year) with columns for eight
> different types of school work -- classroom, homework, field trips, etc.
>
> What I have done is create a log that can be updated one week at a time.
> This shouldn't be a problem for parents who keep their log up to date. But
> if you want to tinker with the hours for more than one week, it will not
be
> a "feature" that you must update each week separately.
>
> So (now we get to the reason for this message) it occurs to be that if I
> could retrieve the 39 weekly records as an array of weeks, I would have a
> structure that I could then update in a single step.
>
> This is what my mysql_fetch_array looks like:
>
> while ($row = mysql_fetch_array($result)) {
>  $week_no = $row['week_no'];
>  $week_date = $row['week_date'];
>  $parent_id = $row['parent_id'];
>  $student_id = $row['student_id'];
>  $class_id = $row['class_id'];
>  $classroom = $row['classroom'];
>  $homework = $row['homework'];
>  $library = $row['library'];
>  $fieldtrip = $row['fieldtrip'];
>  $pta = $row['pta'];
>  $mast = $row['mast'];
>  $meetings = $row['meetings'];
>  $other = $row['other'];
>
> I then create a table row of the result and loop through.
>
> A sample table cell looks like this:
>
> <td align=\"center\">
>   <input type=\"text\" name=\"classroom\" value=\"$classroom\" size=\"2\"
> maxlength=\"4\">
>   </td>
>
> How would I change the mysql_fetch_array to create an array of weeks and
how
> would I change the table output coding to accommodate such an array?
>
> TIA
>
> John Hughes
>
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to