Re: Can you l put a mysql statement in a while loop?
| From: | Jan-Eric Duden | Date: | Fri, 27 Oct 2000 06:49:34 +0000 |
| Subject: | Re: Can you l put a mysql statement in a while loop? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-22279@lists.php.net to get a copy of this message | ||
no...
you missed the little point in the statement :
> > $statement.="UPDATE table SET value=$v WHERE id=$id;";
^
thus the result of the while loop will be for example:
$statement==
"UPDATE table SET value=a WHERE id=2;UPDATE table SET value=b WHERE
id=3;UPDATE table SET value=c WHERE id=4;UPDATE table SET value=d WHERE
id=5;UPDATE table SET value=e WHERE id=6;"
Eric
> Thats not gona do it.... you wont get your results like that.
>
> what you need is this.
>
>
> while(list($id,$v)=each($myarray))
> {
> $statement="UPDATE table SET value=$v WHERE id=$id;";
> $result=mysql_query($statement);
>
> }
>
>
> ----- Original Message -----
> From: "Jan-Eric Duden" <duden@uwyo.edu>
> To: "Shane McBride" <php@riversidedesigns.net>; "Php-General"
> <php-general@lists.php.net>
> Sent: Thursday, October 26, 2000 11:27 PM
> Subject: Re: [PHP] Can you l put a mysql statement in a while loop?
>
>
> > What about this here?
> >
> > $statement="";
> > while(list($id,$v)=each($myarray))
> > {
> > $statement.="UPDATE table SET value=$v WHERE id=$id;";
> > }
> >
> > $result=mysql_query($statement);
> >
> > Eric
> >
> > ----- Original Message -----
> > From: "Shane McBride" <php@riversidedesigns.net>
> > To: "Php-General" <php-general@lists.php.net>
> > Sent: Thursday, October 26, 2000 9:19 PM
> > Subject: [PHP] Can you l put a mysql statement in a while loop?
> >
> >
> > I have an array that contains new values for a table. Can I use an
> "update"
> > statement in a while loop?
> >
> > I seems like a lot of overkill and waste of resources.
> >
> > Any better ideas (heck, ideas that will work would be cool).
> >
> > Nothing found elsewhere...
> >
> > TIA,
> > Shane
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail: php-list-admin@lists.php.net
> >
> >
>