Creating an array of mySQL results with PHP
| From: | John Hughes, Jomari Works | Date: | Tue, 12 Mar 2002 06:42:06 +0000 |
| Subject: | Creating an array of mySQL results with PHP | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-17618@lists.php.net to get a copy of this message | ||
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