Re: for loop problem?
| From: | Christopher William Wesley | Date: | Tue, 13 Nov 2001 06:09:27 +0000 |
| Subject: | Re: for loop problem? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-74376@lists.php.net to get a copy of this message | ||
I just ran your code as you pasted earlier, and set up a mysql database
with the table defined below ... and it inserted 223,110 passcodes into
the table.
PHP 4.0.99-3 (Identifies itself as 4.1.0RC1)
MySQL 3.23.43-3
~Chris /"\
\ / September 11, 2001
X We Are All New Yorkers
/ \ rm -rf /bin/laden
On Mon, 12 Nov 2001, Tyler Longren wrote:
> Hi John,
>
> MySQL Version: MySQL 3.23.44-nt
>
> SQL:
> CREATE TABLE passcodes (
> id int(11) NOT NULL auto_increment,
> passcode varchar(255) NOT NULL default '',
> PRIMARY KEY (id),
> KEY id (id,passcode)
> ) TYPE=MyISAM;
>
> I'm beginning to think it's a MySQL problem also because this PHP SHOULD
> work.
>
> Tyler
>
> ----- Original Message -----
> From: "John Steele" <overlord@visionww.com>
> To: "PHP General List" <php-general@lists.php.net>
> Sent: Monday, November 12, 2001 3:33 PM
> Subject: Re: [PHP] for loop problem?
>
>
> > Hi Tyler,
> >
> > This doesn't sound like a problem with PHP, but MySQL. Can you show
> your CREATE TABLE and MySQL version?
> >
> > John
> >
> > >Hi Martin,
> > >
> > >I just got done doing that, and i got the same thing! :-(
> > >
> > >Here's something interesting though. There's an id field that's set to
> > >AUTO_INCREMENT. I did a "SELECT * FROM passcodes WHERE
> passcode='P1000000'"
> > >This gave me this:
> > >
> > >id | passcode
> > >-----------------------
> > >1 | P1000000
> > >82145 | P1000000
> > >209398 | P1000000
> > >
> > >Shouldn't the ID's be further apart than that? Know what I'm saying?
> > >
> > >Tyler
> > >
> > >----- Original Message -----
> > >From: "Martin Towell" <martin.towell@world.net>
> > >To: "'Tyler Longren'" <tyler@captainjack.com>; "Jack
> > >Dempsey"
> > ><dempsejn@georgetown.edu>
> > >Cc: "PHP-General" <php-general@lists.php.net>
> > >Sent: Monday, November 12, 2001 10:45 PM
> > >Subject: RE: [PHP] for loop problem?
> > >
> > >
> > >> How about changing the logic lightly? try this:
> > >>
> > >> $value1 = 0;
> > >> $value2 = 223109;
> > >> for($i=$value1; $i<=$value2; $i++) {
> > >> $tmp = sprintf("1%06d\n", $i);
> > >> mysql_query("INSERT INTO passcodes (passcode) VALUES
> > >> ('P$tmp')");
> > >>
> > >> basically taking away 1,000,000 from the numbers then adding it back on
> > >> later
> > >>
> > >> Martin T
> > >>
> > >> -----Original Message-----
> > >> From: Tyler Longren [mailto:tyler@captainjack.com]
> > >> Sent: Tuesday, November 13, 2001 3:38 PM
> > >> To: Jack Dempsey
> > >> Cc: PHP-General
> > >> Subject: Re: [PHP] for loop problem?
> > >>
> > >>
> > >> I've ran it a few times without the MySQL code in there. Runs just
> fine
> > >> that way for me too. After it's run a few times for me (with the MySQL
> > >> code), I start getting duplicate entries of codes in there. For
> example,
> > >> I'll end up with a few 'P1000000' entries in the
> > >> 'passcodes' field.
> > >>
> > >> Oh well, here I come perl!
> > >>
> > >> Thanks,
> > >> Tyler
> > >>
> > >> ----- Original Message -----
> > >> From: "Jack Dempsey" <dempsejn@georgetown.edu>
> > >> To: "Tyler Longren" <tyler@captainjack.com>;
> <php-general@lists.php.net>
> > >> Sent: Monday, November 12, 2001 10:43 PM
> > >> Subject: RE: [PHP] for loop problem?
> > >>
> > >>
> > >> > ran it (without mysql queries) and worked fine....real strange.....
> > >> > have you tried the loop without the mysql queries?
> > >> >
> > >> > -----Original Message-----
> > >> > From: Tyler Longren [mailto:tyler@captainjack.com]
> > >> > Sent: Monday, November 12, 2001 11:28 PM
> > >> > To: Jack Dempsey; php-general@lists.php.net
> > >> > Subject: Re: [PHP] for loop problem?
> > >> >
> > >> >
> > >> > Exact code:
> > >> > <?
> > >> > $connection =
> > >> > mysql_connect("host_here","user_here","pass_here");
> > >> > $db = mysql_select_db("db_here", $connection);
> > >> > $value1 = 1000000;
> > >> > $value2 = 1223109;
> > >> > for($i=$value1; $i<=$value2; $i++) {
> > >> > mysql_query("INSERT INTO passcodes (passcode) VALUES
> > >> > ('P$i')");
> > >> > if (mysql_error() != "") {
> > >> > print "<font face=Arial
> > >> > size=2>".mysql_error()."</font>";
> > >> > exit;
> > >> > }
> > >> > }
> > >> > mysql_close($connection);
> > >> > ?>
> > >> >
> > >> > Tyler
> > >> >
> > >> > ----- Original Message -----
> > >> > From: "Jack Dempsey" <dempsejn@georgetown.edu>
> > >> > To: <php-general@lists.php.net>
> > >> > Sent: Monday, November 12, 2001 10:34 PM
> > >> > Subject: RE: [PHP] for loop problem?
> > >> >
> > >> >
> > >> > > paste the complete code in and myself and others can run your exact
> > >copy
> > >> > >
> > >> > > -----Original Message-----
> > >> > > From: Tyler Longren [mailto:tyler@captainjack.com]
> > >> > > Sent: Monday, November 12, 2001 11:22 PM
> > >> > > To: Martin Towell; php-general@lists.php.net
> > >> > > Subject: Re: [PHP] for loop problem?
> > >> > >
> > >> > >
> > >> > > I removed all of the quotes that could be affecting it. Still, it
> > >loops
> > >> > > until I stop it. I let it go all the way up to 350,000 or so. Any
> > >> other
> > >> > > ideas anyone?
> > >> > >
> > >> > > Thank you!
> > >> > > Tyler
> > >> > >
> > >> > > ----- Original Message -----
> > >> > > From: "Martin Towell" <martin.towell@world.net>
> > >> > > To: <php-general@lists.php.net>
> > >> > > Sent: Monday, November 12, 2001 10:06 PM
> > >> > > Subject: RE: [PHP] for loop problem?
> > >> > >
> > >> > >
> > >> > > > hmmm... I just tried :
> > >> > > >
> > >> > > > $value1 = 1000000;
> > >> > > > $value2 = 1223109;
> > >> > > > for($i = $value1; $i <= $value2; $i++)
> > >> > > > {
> > >> > > > echo "$i\n";
> > >> > > > }
> > >> > > >
> > >> > > > and it spat out all 223109 numbers (albiet after a VERY long
> time)
> > >> > > > can't see how adding mysql code would affect the loop...
> > >> > > >
> > >> > > > Martin T
> > >> > > >
> > >> > > > -----Original Message-----
> > >> > > > From: Tyler Longren [mailto:tyler@captainjack.com]
> > >> > > > Sent: Tuesday, November 13, 2001 2:53 PM
> > >> > > > To: Evan Nemerson; php-general@lists.php.net
> > >> > > > Subject: Re: [PHP] for loop problem?
> > >> > > >
> > >> > > >
> > >> > > > To everyone that said it had something to do with the quotes:
> > >> > > > that has nothing to do with it.
> > >> > > >
> > >> > > > When I first wrote this, It didn't have all the quotes. It
> > >> > > > did
> the
> > >> same
> > >> > > > thing. Then, I thought I may need some quotes somewhere, but
> that
> > >> > > obviously
> > >> > > > didn't help. Any other suggestions? If I HAVE to, I'll
> > >> > > > do this
> in
> > >> > PERL,
> > >> > > > but would much rather do it in PHP.
> > >> > > >
> > >> > > > Thanks everyone,
> > >> > > > Tyler
> > >> > > >
> > >> > > > ----- Original Message -----
> > >> > > > From: "Evan Nemerson" <evan@coeus-group.com>
> > >> > > > To: "Tyler Longren" <tyler@captainjack.com>;
> > >> <php-general@lists.php.net>
> > >> > > > Sent: Monday, November 12, 2001 9:41 PM
> > >> > > > Subject: Re: [PHP] for loop problem?
> > >> > > >
> > >> > > >
> > >> > > > > My word why all the quotes?
> > >> > > > >
> > >> > > > > <?
> > >> > > > > $connection =
> > >> > > > > mysql_connect("blah","blah","blah");
> > >> > > > > $db = mysql_select_db("db_to_use", $connection);
> > >> > > > > $value1 = 1000000;
> > >> > > > > $value2 = 1223109;
> > >> > > > > for($i=$value1; $i<=$value2; $i++) {
> > >> > > > > mysql_query("INSERT INTO passcodes (passcode) VALUES
> ('P$i')");
> > >> > > > > if (mysql_error() != "") {
> > >> > > > > print "<font face=Arial
> > >> > > > > size=2>".mysql_error()."</font>";
> > >> > > > > exit;
> > >> > > > > }
> > >> > > > > }
> > >> > > > > mysql_close($connection);
> > >> > > > > ?>
> > >> > > > >
> > >> > > > > That should give you some better results.
> > >> > > > >
> > >> > > > >
> > >> > > > > On Monday 12 November 2001 07:32 pm, you wrote:
> > >> > > > > > Hello everyone,
> > >> > > > > >
> > >> > > > > > I have a pretty big list of codes that need to be put
> > >> > > > > > into a
> > >mysql
> > >> > db.
> > >> > > > The
> > >> > > > > > numbers range from 1000000 to 1223109. Here's the
> > >> > > > > > PHP I
> wrote
> > >to
> > >> > put
> > >> > > > these
> > >> > > > > > codes into a database:
> > >> > > > > >
> > >> > > > > > <?
> > >> > > > > > $connection =
> > >> > > > > > mysql_connect("blah","blah","blah");
> > >> > > > > > $db = mysql_select_db("db_to_use",
> > >> > > > > > $connection);
> > >> > > > > > $value1 = "1000000";
> > >> > > > > > $value2 = "1223109";
> > >> > > > > > for($i="$value1"; $i<="$value2";
> > >> > > > > > $i++) {
> > >> > > > > > mysql_query("INSERT INTO passcodes (passcode)
> > >> > > > > > VALUES
> ('P$i')");
> > >> > > > > > if (mysql_error() != "") {
> > >> > > > > > print "<font face=Arial
> > >> > > > > > size=2>".mysql_error()."</font>";
> > >> > > > > > exit;
> > >> > > > > > }
> > >> > > > > > }
> > >> > > > > > mysql_close($connection);
> > >> > > > > > ?>
> > >> > > > > >
> > >> > > > > > Everytime I run this from a browser, it just keeps
> > >> > > > > > looping.
> It
> > >> > should
> > >> > > > put
> > >> > > > > > about 223109 entries into the "passcodes"
> > >> > > > > > table. However, it
> > >just
> > >> > > keeps
> > >> > > > > > looping. I'll end up with 400,000 or so entries
> > >> > > > > > before I
> stop
> > >it.
> > >> > I
> > >> > > > make
> > >> > > > > > sure I empty that table before I start running it again.
> > >> > > > > > Why
> is
> > >> > this
> > >> > > > > > happening?
> > >> > > > > >
> > >> > > > > > Thanks everyone,
> > >> > > > > > Tyler
> >
> > --
> > /* SteeleSoft Consulting John Steele - Systems Analyst/Programmer
> > * We also walk dogs... Dynamic Web Design PHP/MySQL/Linux/Hosting
> > * www.steelesoftconsulting.com jsteele@steelesoftconsulting.com
> > */
> >
> > --
> > 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
>
>
> --
> 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
>
>