RE: [PHP-DB] Creating an array of mySQL results with PHP

From: Date: Tue, 12 Mar 2002 06:50:12 +0000
Subject: RE: [PHP-DB] Creating an array of mySQL results with PHP
Groups: php.db 
Request: Send a blank email to php-db+get-17619@lists.php.net to get a copy of this message
Well, you could use the power of PHP arrays and just name your input fields in such a way that would create an array upon submittal. For example: <td align=\"center\"> <input type=\"text\" name=\"log[$week_no][classroom]\" value=\"$classroom\"> </td> Then, after submittal, you just loop through the array $log like such: foreach($log as $week_no => $data) { $sql = "UPDATE table SET classroom='{$data['classroom']}' WHERE week_no=$week_no"; mysql_query($sql); } Of course, this all assumes that the key is week_no. Hope this helps, Court > -----Original Message----- > From: John Hughes, Jomari Works [mailto:john@jomari.com] > Sent: Monday, March 11, 2002 10:42 PM > To: php-db@lists.php.net > Subject: [PHP-DB] Creating an array of mySQL results with PHP > > > 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?

« previous php.db (#17619) next »