Re: Help-Updating multiple records
| From: | David Robley | Date: | Fri, 22 Sep 2000 04:41:30 +0000 |
| Subject: | Re: Help-Updating multiple records | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-17284@lists.php.net to get a copy of this message | ||
On Fri, 22 Sep 2000, Adriano Manocchia wrote:
> I'm not sure if this is more of a PHP or MySQL question, but I'm hoping I can get
> some help with it here.
>
> I've got a form being generated from a MySQL query that shows several record names and
> makes an input box for each record. After it, there's a submit button. My problem is I
> can't figure out how to make it update the field of each of the records shown from the data in
> the input boxes by just pressing the one submit button.
>
> Suspect bit of code:
>
> if ($submit) {
> $sql="UPDATE samples SET (quality) VALUES ('$quality') WHERE
> id='$id'";
> $result=mysql_query($sql);
> echo "<b>Info added.</b>";
> }
>
> elseif ($number) {
> echo "<form method='post'>";
> $result=mysql_query("SELECT * FROM samples WHERE ordnum='$number'",$db);
> while ($myrow = mysql_fetch_array($result))
> {
> printf("%s <input type='text' name='quality' size='50'
> maxlength='100'><br>",$myrow["name"]);
> }
>
> echo "<br><input type='submit' name='submit'
> value='Enter quality info'><br></form>";
> }
>
> So I want to update all the "quality" fields of each of the displayed records. I know
> this doesn't work as-is, but if anyone has any ideas of how I might be able to do that with
> just the one submit button, I'd love to hear it. Thanks.
>
> Age
You might try declaring quality as quality[] in the input form; then it
will become an array and should pass through the values for all the fields,
not just the last one. Looks like you'll also need to pass an array with
the values for ID in it.
Then, in the update section, you can loop through the elements of the id
and quality arrays and create an update query for each item. BTW your
UPDATE syntax is wrong!
UPDATE table SET col_name1=expr1, col_name2=expr2,... [WHERE where_def]
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA