Re: Can you l put a mysql statement in a while loop?
| From: | Jan-Eric Duden | Date: | Fri, 27 Oct 2000 07:14:57 +0000 |
| Subject: | Re: Can you l put a mysql statement in a while loop? | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-22282@lists.php.net to get a copy of this message | ||
sorry about that ...
it works on the mysql prompt and with phpMyAdmin (probably they generate
multiple queries,too)
but not with with mysql_query :(
only your example will work
ill need some sleep :)
Eric
----- Original Message -----
From: "Dallas Kropka" <dallask@firstworld.net>
To: "Jan-Eric Duden" <duden@uwyo.edu>
Sent: Friday, October 27, 2000 3:06 AM
Subject: Re: [PHP] Can you l put a mysql statement in a while loop?
> Ah.... will that work tho? having multiple updates strings in a query like
> that?
>
>
> ----- Original Message -----
> From: "Jan-Eric Duden" <duden@uwyo.edu>
> To: "Dallas Kropka" <dallask@firstworld.net>; "Shane McBride"
> <php@riversidedesigns.net>; "Php-General" <php-general@lists.php.net>
> Sent: Thursday, October 26, 2000 11:49 PM
> Subject: Re: [PHP] Can you l put a mysql statement in a while loop?
>
>
> > 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
> > > >
> > > >
> > >
> >
> >
>