You don't need to apologize for being new to PHP or for not understanding
what I have suggested.  We all have to start somewhere.  I fully understand
what you are trying to do--postnuke, as well as multiple sites of my own use
the method that I describe to do multiple row updates simultaneously.

The best way to really understand what is going on would be to run a simple
file (please bare with):

####SNIP####
<?php
  // you might need to replace "$PHP_SELF" with "$SCRIPT_NAME"
  $data = $_POST['data'];       // just in case register_globals is off
  echo <<<EOD
<form action="$PHP_SELF" method="post">
<input type="text" name="data[var1]" value="{$data['var1']}">
<input type="submit">
</form>
EOD;
?>
####SNIP####


The above snippit works because the $data array is filled directly from the
form post.  But, when you want to fill the inputs from a database, your
data-source is different, but you can fudge it as the following code
demonstrates:

<?php
function printForm($data = '') {
  if (!is_array($data)) {
    // do the query
    // fill $data from database query from $result
    while (list($key, $val) = mysql_fetch_array($result)) {
      $data[$key] = $val;
    }
  }

  echo "<form action='$PHP_SELF' method='post'>";
  foreach($data as $key => $val) {
    echo "<input type='text' name='data[$key]' value='$val'>";
  }
  echo "<input type='submit' value='Update'></form>";
}
printForm($_POST['data']);
?>


As you can see, the form has a variable number of elements whose names and
values match what is in the database the first time the script is run, but
take in the updated values when the form is submitted.  I hope this has
helped clear things up.

Here are some links that might shed some more light on the subject:
http://www.php.net/manual/en/language.variables.external.php
http://www.php.net/manual/en/language.variables.variable.php

Now that I have the sql and the source (output source of the demo), I can
code a complete loop for you, but I am tired (I am going on a 16 hours of
work now).  If you would be so kind as sending me demo/parent_log.php
(without passwords), that would save me the time of re-typing a lot if you
feel it would help you.

Court

> -----Original Message-----
> From: John Hughes [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, March 12, 2002 12:08 AM
> To: Shrock, Court; [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] Creating an array of mySQL results with PHP
> 
> 
> First, I admit to being VERY new to PHP and mySQL and, to make matters
> worse, I'm self-taught..
> 
> If you visit the demo site at http://fuzzheads.org/demo you 
> might better
> understand what I'm attempting to do and that might help 
> better explain my
> confusion with your suggestion.
> 
> The Parent Log displays the existing data for each week (up 
> to the current
> week, but not into the rest of the school year) divided into 
> eight possible
> types of work.
> 
> This is what the sql looks like:
> 
> $sql = "
>  SELECT weeks.*, parentlog.*
>  FROM weeks LEFT JOIN parentlog USING(week_no)
>  WHERE parentlog.parent_id = \"$parent_id\"
>  AND parentlog.student_id = \"$student_id\"
>  AND week_date <= CURRENT_DATE
>  ";
> 
> The _existing_ values are placed in the VALUE for each form 
> input in code
> like this:
> 
> <input type=\"text\" name=\"classroom\" value=\"$classroom\" 
> size=\"2\"
> maxlength=\"4\">
> Hidden values for the $week_no, $parent_id and $student_id 
> are included in
> each row.
> 
> Since I'm starting with the existing value for each field, 
> I'm confused by
> your suggestion that the name reference as an array would be 
> different from
> the value reference.
> 
> What I'm shooting for is the ability of the parent to change 
> any existing
> value in any field in any week and then press a single Update 
> button and
> have all of the values updated.
> 
> John Hughes
> 
> 
> ----- Original Message -----
> From: "Shrock, Court" <[EMAIL PROTECTED]>
> To: "'John Hughes, Jomari Works'" <[EMAIL PROTECTED]>; "Shrock, Court"
> <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Monday, March 11, 2002 11:10 PM
> Subject: RE: [PHP-DB] Creating an array of mySQL results with PHP
> 
> 
> > Actually, you want the value of the input to be just 
> "$classroom".  That
> is
> > because it is within the while loop.  Can I ask for a little more
> > information regarding the structure of the table that you are
> querying--what
> > is(are) the primary keys in the table; I am assuming that 
> the "week_no"
> > field is the primary key.  I am sorry for the 
> confusion--the complete code
> > for outputting the input form follows (minus the 
> appropriate form tags).
> >
> > ###SNIP####
> > echo "<table>";
> > 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'];
> >
> >  echo <<<EOD
> > <tr><td align=\"center\">
> >   <input type=\"text\" name=\"log[$week_no][classroom]\"
> > value=\"$classroom\">
> > </td></tr>
> > EOD;
> >
> > }
> > echo "</table><";
> > ###SNIP####
> >
> >
> > > -----Original Message-----
> > > From: John Hughes, Jomari Works [mailto:[EMAIL PROTECTED]]
> > > Sent: Monday, March 11, 2002 11:03 PM
> > > To: Shrock, Court; [EMAIL PROTECTED]
> > > Subject: Re: [PHP-DB] Creating an array of mySQL results with PHP
> > >
> > >
> > > OK. I can see how that works, assuming that the value would be
> > > \"log[$week_no][classroom]\" as well.
> > >
> > > What would the mysql_fetch_array look like?
> >
> > --
> > 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