Re: [PHP] For Loop
On Tuesday 20 June 2006 15:14, Albert Padley wrote: > I have a regular for loop - for($i=1; $i<100; $i++) > > Within the loop I need to create variables named: > > $p1name; > $p2name; > $p3name; > etc. > > The integer portion of each variable name needs to be the value of $i. > > I can't seem to get my syntax correct? > > Can someone point me in the right direction? > > Thanks. > > Albert Padley If you really want to keep the p?name syntax, I would suggest throwing them in an array with keys. $arr["p1name"] $arr["p2name"] Then that way you can create the key dynamically: $arr["p".$i."name"] Not pretty, but it works. Thanks, -- Ray Hauge Programmer/Systems Administrator American Student Loan Services www.americanstudentloan.com 1.800.575.1099 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] For Loop
for($i=1; $i<100; $i++) { ${'p'.$i.'name'} = 'whatever'; } - jeff On 20-Jun-06, at 6:14 PM, Albert Padley wrote: I have a regular for loop - for($i=1; $i<100; $i++) Within the loop I need to create variables named: $p1name; $p2name; $p3name; etc. The integer portion of each variable name needs to be the value of $i. I can't seem to get my syntax correct? Can someone point me in the right direction? Thanks. Albert Padley -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] For Loop
Ray Hauge wrote: On Tuesday 20 June 2006 15:14, Albert Padley wrote: I have a regular for loop - for($i=1; $i<100; $i++) Within the loop I need to create variables named: $p1name; $p2name; $p3name; etc. The integer portion of each variable name needs to be the value of $i. I can't seem to get my syntax correct? Can someone point me in the right direction? Thanks. Albert Padley If you really want to keep the p?name syntax, I would suggest throwing them in an array with keys. $arr["p1name"] $arr["p2name"] Then that way you can create the key dynamically: $arr["p".$i."name"] Not pretty, but it works. Thanks, I haven't checked this, but couldn't you reference it as $arr["p$iname"] ? Is there a reason why variable expansion wouldn't work in this circumstance? If it does, you could make it easier to read by doing $arr["p{$i}name"] even though the {} aren't required. It'd be a lot easier to read than concatenations :) Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] For Loop
Are you sure that you don't want an array? Arrays are normally much better for this type of thing. That said, ${"p{$i}name"} = 'foo'; David Albert Padley wrote: > I have a regular for loop - for($i=1; $i<100; $i++) > > Within the loop I need to create variables named: > > $p1name; > $p2name; > $p3name; > etc. > > The integer portion of each variable name needs to be the value of $i. > > I can't seem to get my syntax correct? > > Can someone point me in the right direction? > > Thanks. > > Albert Padley > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] For Loop
On Tuesday 20 June 2006 15:28, Adam Zey wrote: > Ray Hauge wrote: > > On Tuesday 20 June 2006 15:14, Albert Padley wrote: > >> I have a regular for loop - for($i=1; $i<100; $i++) > >> > >> Within the loop I need to create variables named: > >> > >> $p1name; > >> $p2name; > >> $p3name; > >> etc. > >> > >> The integer portion of each variable name needs to be the value of $i. > >> > >> I can't seem to get my syntax correct? > >> > >> Can someone point me in the right direction? > >> > >> Thanks. > >> > >> Albert Padley > > > > If you really want to keep the p?name syntax, I would suggest throwing > > them in an array with keys. > > > > $arr["p1name"] > > $arr["p2name"] > > > > Then that way you can create the key dynamically: > > > > $arr["p".$i."name"] > > > > Not pretty, but it works. > > > > Thanks, > > I haven't checked this, but couldn't you reference it as $arr["p$iname"] > ? Is there a reason why variable expansion wouldn't work in this > circumstance? > > If it does, you could make it easier to read by doing $arr["p{$i}name"] > even though the {} aren't required. It'd be a lot easier to read than > concatenations :) > > Regards, Adam. Both of those ways work. I think there's a question on the PHP Certification Exam about the different ways to work with strings. -- Ray Hauge Programmer/Systems Administrator American Student Loan Services www.americanstudentloan.com 1.800.575.1099 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] For Loop
Thanks everyone. Always nice to know there is more than one direction to go in. Albert On Jun 20, 2006, at 4:52 PM, Ray Hauge wrote: On Tuesday 20 June 2006 15:28, Adam Zey wrote: Ray Hauge wrote: On Tuesday 20 June 2006 15:14, Albert Padley wrote: I have a regular for loop - for($i=1; $i<100; $i++) Within the loop I need to create variables named: $p1name; $p2name; $p3name; etc. The integer portion of each variable name needs to be the value of $i. I can't seem to get my syntax correct? Can someone point me in the right direction? Thanks. Albert Padley If you really want to keep the p?name syntax, I would suggest throwing them in an array with keys. $arr["p1name"] $arr["p2name"] Then that way you can create the key dynamically: $arr["p".$i."name"] Not pretty, but it works. Thanks, I haven't checked this, but couldn't you reference it as $arr["p $iname"] ? Is there a reason why variable expansion wouldn't work in this circumstance? If it does, you could make it easier to read by doing $arr["p{$i} name"] even though the {} aren't required. It'd be a lot easier to read than concatenations :) Regards, Adam. Both of those ways work. I think there's a question on the PHP Certification Exam about the different ways to work with strings. -- Ray Hauge Programmer/Systems Administrator American Student Loan Services www.americanstudentloan.com 1.800.575.1099 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] For Loop
On Tue, 2006-06-20 at 19:19, Albert Padley wrote: > Thanks everyone. Always nice to know there is more than one direction > to go in. > > Albert > > > On Jun 20, 2006, at 4:52 PM, Ray Hauge wrote: > > > On Tuesday 20 June 2006 15:28, Adam Zey wrote: > >> Ray Hauge wrote: > >>> On Tuesday 20 June 2006 15:14, Albert Padley wrote: > I have a regular for loop - for($i=1; $i<100; $i++) > > Within the loop I need to create variables named: > > $p1name; > $p2name; > $p3name; > etc. > > The integer portion of each variable name needs to be the value > of $i. > > I can't seem to get my syntax correct? > > Can someone point me in the right direction? > > Thanks. > > Albert Padley > >>> > >>> If you really want to keep the p?name syntax, I would suggest > >>> throwing > >>> them in an array with keys. > >>> > >>> $arr["p1name"] > >>> $arr["p2name"] > >>> > >>> Then that way you can create the key dynamically: > >>> > >>> $arr["p".$i."name"] > >>> > >>> Not pretty, but it works. > >>> > >>> Thanks, > >> > >> I haven't checked this, but couldn't you reference it as $arr["p > >> $iname"] > >> ? Is there a reason why variable expansion wouldn't work in this > >> circumstance? > >> > >> If it does, you could make it easier to read by doing $arr["p{$i} > >> name"] > >> even though the {} aren't required. It'd be a lot easier to read than > >> concatenations :) > >> > >> Regards, Adam. > > > > Both of those ways work. I think there's a question on the PHP > > Certification > > Exam about the different ways to work with strings. Ahhh, got to love the fact that there's a question, yet no need for the taker to actually understand the implications. Does anyone know if you can get toilet paper with certs printed on it? Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] For Loop
Albert Padley wrote: Thanks everyone. Always nice to know there is more than one direction to go in. A alternative to variable variables might use these: http://us3.php.net/manual/en/function.compact.php http://us3.php.net/manual/en/function.extract.php 'extract' looks like it might be right up your alley: Dante On Tuesday 20 June 2006 15:14, Albert Padley wrote: I have a regular for loop - for($i=1; $i<100; $i++) Within the loop I need to create variables named: $p1name; $p2name; $p3name; etc. The integer portion of each variable name needs to be the value of $i. I can't seem to get my syntax correct? Can someone point me in the right direction? Thanks. Albert Padley -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] For Loop
What happens is (if I understand it correctly): First, PHP sets $i to equal 0, and then immediately sets $i to $months_arr_length. Every time the loop executes, it resets $1 to $months_arr_length, so you are stuck in an infinite loop. The reason behind this is you are using assignment equals (=) instead of comparison equals(==). It's a mistake I've made myself quite a few times. As an aside, a neater way of using a for loop on an array is the following: foreach ($months_arr as $key => $value) { echo $value.""; } On 8 Dec 2004, at 22:41, R. Van Tassel wrote: I have a question about the following code: ** $months_arr = array("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"); $months_arr_length = count($months_arr); for($i = 0; $i = $months_arr_length; $i++){ echo $months_arr[1]." "; } *** When I run the code above it continues and never stops. According to the PHP documentation the second condition works as follows: "In the beginning of each iteration, expr2 is evaluated. If it evaluates to TRUE, the loop continues and the nested statement(s) are executed. If it evaluates to FALSE, the execution of the loop ends." In the first iteration of the loop $i would equal 0 and the array length is 12. 12 is consistent. To it seems that the loop should STOP when the counter reaches 12, equal to the length of the array. Why is it continuing in a neverending loop? What am I missing? Changing the condition of the for loop to $i <= $months_arr_length; fixes everything and it works properly. Can someone please explain where my confusion is? Thanks, ~R. Van Tassel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] For Loop
$i = $months_arr_length is an assignment, not a comparison, so it will always evaluate to true, and you are setting your counter var to 12 every time the loop runs, that's why it runs infinitely. > > From: "R. Van Tassel" <[EMAIL PROTECTED]> > Date: 2004/12/08 Wed PM 04:41:00 EST > To: "'PHP general'" <[EMAIL PROTECTED]> > Subject: [PHP] For Loop > > I have a question about the following code: > > ** > > $months_arr = array("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", > "SEP", "OCT", "NOV", "DEC"); > $months_arr_length = count($months_arr); > > for($i = 0; $i = $months_arr_length; $i++){ > echo $months_arr[1]." "; > } > > *** > > When I run the code above it continues and never stops. According to the PHP > documentation the second condition works as follows: > > "In the beginning of each iteration, expr2 is evaluated. If it evaluates to > TRUE, the loop continues and the nested statement(s) are executed. If it > evaluates to FALSE, the execution of the loop ends." > > In the first iteration of the loop $i would equal 0 and the array length is > 12. 12 is consistent. To it seems that the loop should STOP when the counter > reaches 12, equal to the length of the array. Why is it continuing in a > neverending loop? What am I missing? > > Changing the condition of the for loop to $i <= $months_arr_length; fixes > everything and it works properly. > > Can someone please explain where my confusion is? > > Thanks, > ~R. Van Tassel > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] For Loop
try for($i=0;$i>$months_arr_length;$i++) look at it as this: for(i as starting point; till i is what? greater than my length; increment i how? by 1) { HTH Trav - Original Message - From: "R. Van Tassel" <[EMAIL PROTECTED]> To: "'PHP general'" <[EMAIL PROTECTED]> Sent: Wednesday, December 08, 2004 3:41 PM Subject: [PHP] For Loop I have a question about the following code: ** $months_arr = array("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"); $months_arr_length = count($months_arr); for($i = 0; $i = $months_arr_length; $i++){ echo $months_arr[1]." "; } *** When I run the code above it continues and never stops. According to the PHP documentation the second condition works as follows: "In the beginning of each iteration, expr2 is evaluated. If it evaluates to TRUE, the loop continues and the nested statement(s) are executed. If it evaluates to FALSE, the execution of the loop ends." In the first iteration of the loop $i would equal 0 and the array length is 12. 12 is consistent. To it seems that the loop should STOP when the counter reaches 12, equal to the length of the array. Why is it continuing in a neverending loop? What am I missing? Changing the condition of the for loop to $i <= $months_arr_length; fixes everything and it works properly. Can someone please explain where my confusion is? Thanks, ~R. Van Tassel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop problem
Try this: If ($button != "") { $t = mysql_query("SELECT * from AddExisting"); $number_of_customers = mysql_num_rows($t); for($i=0; $i<$number_of_customers;$i++) { $r = mysql_fetch_array($t); $email = $r["EMAIL_ADDRESS"]; $cusname = $r["Name"]; $originalMessage = $message $to = $email; $subject = "hello"; $message = "Dear $cusname,".$originalMessage; $fromaddress = "[EMAIL PROTECTED]"; mail($to, $subject, $message, $fromaddress); }//end of for }//end of if * * Cal Evans * Techno-Mage * http://www.calevans.com * - Original Message - From: "Kris Vose" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, March 20, 2002 2:07 PM Subject: [PHP] for loop problem I have a problem with a piece of code that uses the mail function in a for loop. It sends out mail to all the users in the database but it has a problem with attaching their specific name into the message. What happens is the first user in the database will get their name in the e-mail (Dear John,). Then the second user in the database will get the last users name and their name in the e-mail (Dear John, Dear Mike) ...and so on and so forth. How do I fix this problem? Your help is appreciated. Here is the code: If ($button != "") { $t = mysql_query("SELECT * from AddExisting"); $number_of_customers = mysql_num_rows($t); for($i=0; $i<$number_of_customers;$i++) { $r = mysql_fetch_array($t); $email = $r["EMAIL_ADDRESS"]; $cusname = $r["Name"]; $to = $email; $subject = "hello"; $message = "Dear $cusname,".$message; $fromaddress = "[EMAIL PROTECTED]"; mail($to, $subject, $message, $fromaddress); }//end of for }//end of if -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop problem
Opps, last messages had the definition of $originalMessage in the wrong place. Try this: If ($button != "") { $t = mysql_query("SELECT * from AddExisting"); $number_of_customers = mysql_num_rows($t); $originalMessage = $message; for($i=0; $i<$number_of_customers;$i++) { $r = mysql_fetch_array($t); $email = $r["EMAIL_ADDRESS"]; $cusname = $r["Name"]; $to = $email; $subject = "hello"; $message = "Dear $cusname,".$originalMessage; $fromaddress = "[EMAIL PROTECTED]"; mail($to, $subject, $message, $fromaddress); }//end of for }//end of if * * Cal Evans * Techno-Mage * http://www.calevans.com * - Original Message - From: "Kris Vose" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, March 20, 2002 2:07 PM Subject: [PHP] for loop problem I have a problem with a piece of code that uses the mail function in a for loop. It sends out mail to all the users in the database but it has a problem with attaching their specific name into the message. What happens is the first user in the database will get their name in the e-mail (Dear John,). Then the second user in the database will get the last users name and their name in the e-mail (Dear John, Dear Mike) ...and so on and so forth. How do I fix this problem? Your help is appreciated. Here is the code: If ($button != "") { $t = mysql_query("SELECT * from AddExisting"); $number_of_customers = mysql_num_rows($t); for($i=0; $i<$number_of_customers;$i++) { $r = mysql_fetch_array($t); $email = $r["EMAIL_ADDRESS"]; $cusname = $r["Name"]; $to = $email; $subject = "hello"; $message = "Dear $cusname,".$message; $fromaddress = "[EMAIL PROTECTED]"; mail($to, $subject, $message, $fromaddress); }//end of for }//end of if -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop problem
On Wed, 20 Mar 2002, Kris Vose wrote: > I have a problem with a piece of code that uses the mail function in a > for loop. It sends out mail to all the users in the database but it has > a problem with attaching their specific name into the message. What > happens is the first user in the database will get their name in the > e-mail (Dear John,). Then the second user in the database will get the > last users name and their name in the e-mail (Dear John, Dear Mike) > ...and so on and so forth. > > If ($button != "") > { > $t = mysql_query("SELECT * from AddExisting"); > $number_of_customers = mysql_num_rows($t); > > for($i=0; $i<$number_of_customers;$i++) > { > $r = mysql_fetch_array($t); > $email = $r["EMAIL_ADDRESS"]; > $cusname = $r["Name"]; > > $to = $email; > $subject = "hello"; > $message = "Dear $cusname,".$message; > $fromaddress = "[EMAIL PROTECTED]"; > > mail($to, $subject, $message, $fromaddress); > }//end of for > }//end of if You don't need a for loop here; you don't actually care specifically how many customers there are, just that you iterate once for each one. And you've put a raw email address in the "extra headers" argument to mail() rather than a properly-formed From: header. Here's the code you want: if (!empty(button)) { $t = mysql_query("SELECT * from AddExisting"); while ($r = mysql_fetch_assoc($t)) { $message = "Dear {$r[name]},\n{$message}"; mail ($r[email_address], 'hello', $message, 'From: [EMAIL PROTECTED]'); } } miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop changes?
From: "Michael Gerholdt" <[EMAIL PROTECTED]> > I want the week and month days to have leading zeros - how can I make the > new environment replicate the old? Loop using the numeric but use printf for the formatting (which is really what you should have used originally). Refer to the manual for the many and varied ways printf can be used. Mark C. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] for loop problem?
try removing the quotes and see if that works eg $value1 = "100"; becomes $value1 = 100; and for($i="$value1"; $i<="$value2"; $i++) { becomes for($i=$value1; $i<=$value2; $i++) { Martin T -Original Message- From: Tyler Longren [mailto:[EMAIL PROTECTED]] Sent: Tuesday, November 13, 2001 2:33 PM To: PHP-General Subject: [PHP] for loop problem? Hello everyone, I have a pretty big list of codes that need to be put into a mysql db. The numbers range from 100 to 1223109. Here's the PHP I wrote to put these codes into a database: ".mysql_error().""; 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] for loop problem?
My word why all the quotes? ".mysql_error().""; 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 100 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 = "100"; > $value2 = "1223109"; > for($i="$value1"; $i<="$value2"; $i++) { > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > if (mysql_error() != "") { > print "".mysql_error().""; > 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
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" <[EMAIL PROTECTED]> To: "Tyler Longren" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> 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 = 100; > $value2 = 1223109; > for($i=$value1; $i<=$value2; $i++) { > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > if (mysql_error() != "") { > print "".mysql_error().""; > 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 100 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 = "100"; > > $value2 = "1223109"; > > for($i="$value1"; $i<="$value2"; $i++) { > > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > > if (mysql_error() != "") { > > print "".mysql_error().""; > > 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 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] for loop problem?
hmmm... I just tried : $value1 = 100; $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:[EMAIL PROTECTED]] Sent: Tuesday, November 13, 2001 2:53 PM To: Evan Nemerson; [EMAIL PROTECTED] 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" <[EMAIL PROTECTED]> To: "Tyler Longren" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> 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 = 100; > $value2 = 1223109; > for($i=$value1; $i<=$value2; $i++) { > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > if (mysql_error() != "") { > print "".mysql_error().""; > 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 100 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 = "100"; > > $value2 = "1223109"; > > for($i="$value1"; $i<="$value2"; $i++) { > > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > > if (mysql_error() != "") { > > print "".mysql_error().""; > > 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 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
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" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, November 12, 2001 10:06 PM Subject: RE: [PHP] for loop problem? > hmmm... I just tried : > > $value1 = 100; > $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:[EMAIL PROTECTED]] > Sent: Tuesday, November 13, 2001 2:53 PM > To: Evan Nemerson; [EMAIL PROTECTED] > 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" <[EMAIL PROTECTED]> > To: "Tyler Longren" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > 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 = 100; > > $value2 = 1223109; > > for($i=$value1; $i<=$value2; $i++) { > > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > > if (mysql_error() != "") { > > print "".mysql_error().""; > > 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 100 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 = "100"; > > > $value2 = "1223109"; > > > for($i="$value1"; $i<="$value2"; $i++) { > > > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > > > if (mysql_error() != "") { > > > print "".mysql_error().""; > > > 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 > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
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:[EMAIL PROTECTED]] Sent: Monday, November 12, 2001 11:22 PM To: Martin Towell; [EMAIL PROTECTED] 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" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, November 12, 2001 10:06 PM Subject: RE: [PHP] for loop problem? > hmmm... I just tried : > > $value1 = 100; > $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:[EMAIL PROTECTED]] > Sent: Tuesday, November 13, 2001 2:53 PM > To: Evan Nemerson; [EMAIL PROTECTED] > 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" <[EMAIL PROTECTED]> > To: "Tyler Longren" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > 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 = 100; > > $value2 = 1223109; > > for($i=$value1; $i<=$value2; $i++) { > > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > > if (mysql_error() != "") { > > print "".mysql_error().""; > > 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 100 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 = "100"; > > > $value2 = "1223109"; > > > for($i="$value1"; $i<="$value2"; $i++) { > > > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > > > if (mysql_error() != "") { > > > print "".mysql_error().""; > > > 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 > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] for loop problem?
Exact code: ".mysql_error().""; exit; } } mysql_close($connection); ?> Tyler - Original Message - From: "Jack Dempsey" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED]] > Sent: Monday, November 12, 2001 11:22 PM > To: Martin Towell; [EMAIL PROTECTED] > 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" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Monday, November 12, 2001 10:06 PM > Subject: RE: [PHP] for loop problem? > > > > hmmm... I just tried : > > > > $value1 = 100; > > $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:[EMAIL PROTECTED]] > > Sent: Tuesday, November 13, 2001 2:53 PM > > To: Evan Nemerson; [EMAIL PROTECTED] > > 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" <[EMAIL PROTECTED]> > > To: "Tyler Longren" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > > 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 = 100; > > > $value2 = 1223109; > > > for($i=$value1; $i<=$value2; $i++) { > > > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > > > if (mysql_error() != "") { > > > print "".mysql_error().""; > > > 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 100 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 = "100"; > > > > $value2 = "1223109"; > > > > for($i="$value1"; $i<="$value2"; $i++) { > > > > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > > > > if (mysql_error() != "") { > > > > print "".mysql_error().""; > > > > 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 > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] for loop problem?
ran it (without mysql queries) and worked finereal strange. have you tried the loop without the mysql queries? -Original Message- From: Tyler Longren [mailto:[EMAIL PROTECTED]] Sent: Monday, November 12, 2001 11:28 PM To: Jack Dempsey; [EMAIL PROTECTED] Subject: Re: [PHP] for loop problem? Exact code: ".mysql_error().""; exit; } } mysql_close($connection); ?> Tyler - Original Message - From: "Jack Dempsey" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED]] > Sent: Monday, November 12, 2001 11:22 PM > To: Martin Towell; [EMAIL PROTECTED] > 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" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Monday, November 12, 2001 10:06 PM > Subject: RE: [PHP] for loop problem? > > > > hmmm... I just tried : > > > > $value1 = 100; > > $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:[EMAIL PROTECTED]] > > Sent: Tuesday, November 13, 2001 2:53 PM > > To: Evan Nemerson; [EMAIL PROTECTED] > > 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" <[EMAIL PROTECTED]> > > To: "Tyler Longren" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > > 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 = 100; > > > $value2 = 1223109; > > > for($i=$value1; $i<=$value2; $i++) { > > > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > > > if (mysql_error() != "") { > > > print "".mysql_error().""; > > > 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 100 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 = "100"; > > > > $value2 = "1223109"; > > > > for($i="$value1"; $i<="$value2"; $i++) { > > > > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > > > > if (mysql_error() != "") { > > > > print "".mysql_error().""; > > > > exit; > > > > } > > > > } > > > > mysql_close($connection); > > > > ?> > > > > > > > > Everytime I run this from a browser, it just keeps looping. It should > > put > > > > about 223109 entries into the "passcodes
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 'P100' entries in the 'passcodes' field. Oh well, here I come perl! Thanks, Tyler - Original Message - From: "Jack Dempsey" <[EMAIL PROTECTED]> To: "Tyler Longren" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Monday, November 12, 2001 10:43 PM Subject: RE: [PHP] for loop problem? > ran it (without mysql queries) and worked finereal strange. > have you tried the loop without the mysql queries? > > -Original Message- > From: Tyler Longren [mailto:[EMAIL PROTECTED]] > Sent: Monday, November 12, 2001 11:28 PM > To: Jack Dempsey; [EMAIL PROTECTED] > 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 = 100; > $value2 = 1223109; > for($i=$value1; $i<=$value2; $i++) { > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > if (mysql_error() != "") { > print "".mysql_error().""; > exit; > } > } > mysql_close($connection); > ?> > > Tyler > > - Original Message - > From: "Jack Dempsey" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > 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:[EMAIL PROTECTED]] > > Sent: Monday, November 12, 2001 11:22 PM > > To: Martin Towell; [EMAIL PROTECTED] > > 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" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > 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:[EMAIL PROTECTED]] > > > Sent: Tuesday, November 13, 2001 2:53 PM > > > To: Evan Nemerson; [EMAIL PROTECTED] > > > 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" <[EMAIL PROTECTED]> > > > To: "Tyler Longren" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > > > 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 = 100; > > > > $value2 = 1223109; > > > > for($i=$value1; $i<=$value2; $i++) { > > > > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > > > > if (mysql_error() != "") { > > > > print "".mysql_error().""; > > > > exit; > > > >
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:[EMAIL PROTECTED]] 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 'P100' entries in the 'passcodes' field. Oh well, here I come perl! Thanks, Tyler - Original Message - From: "Jack Dempsey" <[EMAIL PROTECTED]> To: "Tyler Longren" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Monday, November 12, 2001 10:43 PM Subject: RE: [PHP] for loop problem? > ran it (without mysql queries) and worked finereal strange. > have you tried the loop without the mysql queries? > > -Original Message- > From: Tyler Longren [mailto:[EMAIL PROTECTED]] > Sent: Monday, November 12, 2001 11:28 PM > To: Jack Dempsey; [EMAIL PROTECTED] > 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 = 100; > $value2 = 1223109; > for($i=$value1; $i<=$value2; $i++) { > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > if (mysql_error() != "") { > print "".mysql_error().""; > exit; > } > } > mysql_close($connection); > ?> > > Tyler > > - Original Message - > From: "Jack Dempsey" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > 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:[EMAIL PROTECTED]] > > Sent: Monday, November 12, 2001 11:22 PM > > To: Martin Towell; [EMAIL PROTECTED] > > 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" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > Sent: Monday, November 12, 2001 10:06 PM > > Subject: RE: [PHP] for loop problem? > > > > > > > hmmm... I just tried : > > > > > > $value1 = 100; > > > $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:[EMAIL PROTECTED]] > > > Sent: Tuesday, November 13, 2001 2:53 PM > > > To: Evan Nemerson; [EMAIL PROTECTED] > > > 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" <[EMAIL PROTECTED]> > > > To: "Tyler Longren" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > > > Sent: Monday, November 12, 2001 9:41 PM > > > Subject: Re: [PHP] for loop problem? > > > > > > > > > > My word why all the quotes? > > > > > > > > > > > $connection = mysql_connect("blah",&
Re: [PHP] for loop problem?
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='P100'" This gave me this: id | passcode --- 1 |P100 82145 |P100 209398 |P100 Shouldn't the ID's be further apart than that? Know what I'm saying? Tyler - Original Message - From: "Martin Towell" <[EMAIL PROTECTED]> To: "'Tyler Longren'" <[EMAIL PROTECTED]>; "Jack Dempsey" <[EMAIL PROTECTED]> Cc: "PHP-General" <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED]] > 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 'P100' entries in the 'passcodes' field. > > Oh well, here I come perl! > > Thanks, > Tyler > > - Original Message - > From: "Jack Dempsey" <[EMAIL PROTECTED]> > To: "Tyler Longren" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > Sent: Monday, November 12, 2001 10:43 PM > Subject: RE: [PHP] for loop problem? > > > > ran it (without mysql queries) and worked finereal strange. > > have you tried the loop without the mysql queries? > > > > -Original Message- > > From: Tyler Longren [mailto:[EMAIL PROTECTED]] > > Sent: Monday, November 12, 2001 11:28 PM > > To: Jack Dempsey; [EMAIL PROTECTED] > > 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 = 100; > > $value2 = 1223109; > > for($i=$value1; $i<=$value2; $i++) { > > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > > if (mysql_error() != "") { > > print "".mysql_error().""; > > exit; > > } > > } > > mysql_close($connection); > > ?> > > > > Tyler > > > > - Original Message - > > From: "Jack Dempsey" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > 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:[EMAIL PROTECTED]] > > > Sent: Monday, November 12, 2001 11:22 PM > > > To: Martin Towell; [EMAIL PROTECTED] > > > 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" <[EMAIL PROTECTED]> > > > To: <[EMAIL PROTECTED]> > > > Sent: Monday, November 12, 2001 10:06 PM > > > Subject: RE: [PHP] for loop problem? > > > > > > > > > > hmmm... I just tried : > > > > > > > > $value1 = 100; > > > > $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 > > > &
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='P100'" >This gave me this: > >id | passcode >--- >1 |P100 >82145 |P100 >209398 |P100 > >Shouldn't the ID's be further apart than that? Know what I'm saying? > >Tyler > >- Original Message - >From: "Martin Towell" <[EMAIL PROTECTED]> >To: "'Tyler Longren'" <[EMAIL PROTECTED]>; "Jack Dempsey" ><[EMAIL PROTECTED]> >Cc: "PHP-General" <[EMAIL PROTECTED]> >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:[EMAIL PROTECTED]] >> 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 'P100' entries in the 'passcodes' field. >> >> Oh well, here I come perl! >> >> Thanks, >> Tyler >> >> - Original Message - >> From: "Jack Dempsey" <[EMAIL PROTECTED]> >> To: "Tyler Longren" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> >> Sent: Monday, November 12, 2001 10:43 PM >> Subject: RE: [PHP] for loop problem? >> >> >> > ran it (without mysql queries) and worked finereal strange. >> > have you tried the loop without the mysql queries? >> > >> > -Original Message- >> > From: Tyler Longren [mailto:[EMAIL PROTECTED]] >> > Sent: Monday, November 12, 2001 11:28 PM >> > To: Jack Dempsey; [EMAIL PROTECTED] >> > 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 = 100; >> > $value2 = 1223109; >> > for($i=$value1; $i<=$value2; $i++) { >> > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); >> > if (mysql_error() != "") { >> > print "".mysql_error().""; >> > exit; >> > } >> > } >> > mysql_close($connection); >> > ?> >> > >> > Tyler >> > >> > - Original Message - >> > From: "Jack Dempsey" <[EMAIL PROTECTED]> >> > To: <[EMAIL PROTECTED]> >> > 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:[EMAIL PROTECTED]] >> > > Sent: Monday, November 12, 2001 11:22 PM >> > > To: Martin Towell; [EMAIL PROTECTED] >> > > 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" <[EMAIL PROTECTED]> >> > > To: <[EMAIL PROTECTED]> >> > > Sent: Monday, November 12, 2001 10:06 PM >>
Re: [PHP] for loop problem?
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" <[EMAIL PROTECTED]> To: "PHP General List" <[EMAIL PROTECTED]> 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='P100'" > >This gave me this: > > > >id | passcode > >--- > >1 |P100 > >82145 |P100 > >209398 |P100 > > > >Shouldn't the ID's be further apart than that? Know what I'm saying? > > > >Tyler > > > >- Original Message ----- > >From: "Martin Towell" <[EMAIL PROTECTED]> > >To: "'Tyler Longren'" <[EMAIL PROTECTED]>; "Jack Dempsey" > ><[EMAIL PROTECTED]> > >Cc: "PHP-General" <[EMAIL PROTECTED]> > >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:[EMAIL PROTECTED]] > >> 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 'P100' entries in the 'passcodes' field. > >> > >> Oh well, here I come perl! > >> > >> Thanks, > >> Tyler > >> > >> - Original Message - > >> From: "Jack Dempsey" <[EMAIL PROTECTED]> > >> To: "Tyler Longren" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > >> Sent: Monday, November 12, 2001 10:43 PM > >> Subject: RE: [PHP] for loop problem? > >> > >> > >> > ran it (without mysql queries) and worked finereal strange. > >> > have you tried the loop without the mysql queries? > >> > > >> > -Original Message- > >> > From: Tyler Longren [mailto:[EMAIL PROTECTED]] > >> > Sent: Monday, November 12, 2001 11:28 PM > >> > To: Jack Dempsey; [EMAIL PROTECTED] > >> > 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 = 100; > >> > $value2 = 1223109; > >> > for($i=$value1; $i<=$value2; $i++) { > >> > mysql_query("INSERT INTO passcodes (passcode) VALUES ('P$i')"); > >> > if (mysql_error() != "") { > >> > print "".mysql_error().""; > >> > exit; > >> > } > >> > } > >> > mysql_close($connection); > >> > ?> > >> > > >> > Tyler > >> > > >> > - Original Message - > >> > From: "Jack Dempsey" <[EMAIL PROTECTED]> > >> > To: <[EMAIL PROTECTED]> > >> > Sent: Monday, November 12, 2001 10:34 PM > >> >
Re: [PHP] for loop problem?
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" <[EMAIL PROTECTED]> > To: "PHP General List" <[EMAIL PROTECTED]> > 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='P100'" > > >This gave me this: > > > > > >id | passcode > > >--- > > >1 |P100 > > >82145 |P100 > > >209398 |P100 > > > > > >Shouldn't the ID's be further apart than that? Know what I'm saying? > > > > > >Tyler > > > > > >- Original Message - > > >From: "Martin Towell" <[EMAIL PROTECTED]> > > >To: "'Tyler Longren'" <[EMAIL PROTECTED]>; "Jack Dempsey" > > ><[EMAIL PROTECTED]> > > >Cc: "PHP-General" <[EMAIL PROTECTED]> > > >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:[EMAIL PROTECTED]] > > >> 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 'P100' entries in the 'passcodes' field. > > >> > > >> Oh well, here I come perl! > > >> > > >> Thanks, > > >> Tyler > > >> > > >> - Original Message - > > >> From: "Jack Dempsey" <[EMAIL PROTECTED]> > > >> To: "Tyler Longren" <[EMAIL PROTECTED]>; > <[EMAIL PROTECTED]> > > >> Sent: Monday, November 12, 2001 10:43 PM > > >> Subject: RE: [PHP] for loop problem? > > >> > > >> > > >> > ran it (without mysql queries) and worked finereal strange. > > >> > have you tried the loop without the mysql queries? > > >> > > > >> > -Original Message- > > >> > From: Tyler Longren [mailto:[EMAIL PROTECTED]] > > >> > Sent: Monday, November 12, 2001 11:28 PM > > >> > To: Jack Dempsey; [EMAIL PROTECTED] > > >> > Subject: Re: [PHP] for loop problem? > > >> > > > >> &g
Re: [PHP] for loop problem?
Tyler, It must be something weird with your NT version of MySQL, you might try asking on the MySQL list, or checking the bug list on mysql.com. I have an even older version here on 95, that doesn't display any of those problems. Here's the code I used with it's output (no duplicates, I checked). Notice that I did have to change the CREATE TABLE to meet 3.21.29a-gamma restrictions. You might try changing the passcode to an int, and tacking the 'P' on the front in your application. Not sure if that's possible... John '; if (!$qid = mysql_query("SELECT id,passcode FROM passcodes ORDER BY passcode DESC LIMIT 10")) die ("SELECT failed: ". mysql_error()); while ($arr = mysql_fetch_array($qid)) echo "$arr[0]: $arr[1]\n"; if (!mysql_close($connection)) die ("Can't close connection: ". mysql_error()); ?> And it's output: INSERTs completed. 223110: P1223109 223109: P1223108 223108: P1223107 223107: P1223106 223106: P1223105 223105: P1223104 223104: P1223103 223103: P1223102 223102: P1223101 223101: P1223100 >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" <[EMAIL PROTECTED]> >To: "PHP General List" <[EMAIL PROTECTED]> >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='P100'" >> >This gave me this: >> > >> >id | passcode >> >--- >> >1 |P100 >> >82145 | P1000000 >> >209398 |P100 >> > >> >Shouldn't the ID's be further apart than that? Know what I'm saying? >> > >> >Tyler >> > >> >- Original Message - >> >From: "Martin Towell" <[EMAIL PROTECTED]> >> >To: "'Tyler Longren'" <[EMAIL PROTECTED]>; "Jack Dempsey" >> ><[EMAIL PROTECTED]> >> >Cc: "PHP-General" <[EMAIL PROTECTED]> >> >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:[EMAIL PROTECTED]] >> >> 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 'P100' entries in the 'passcodes' field. >> >> >> >> Oh well, here I come perl! >> >> >> >> Thanks, >> >> Tyler >> >> >> >> - Original Message - >> >> From: "Jack Dempsey" <[EMAIL PROTECTED]> >> >> To: "Tyler Longren" <[EMAIL PROTECTED]>; ><[EMAIL PROTECTED]> >> >> Sent: Monday, November 12, 2001 10:43 PM >> >> Subject: RE: [PHP] for loop problem? >> >> >> >> >> >>
Re: [PHP] for loop problem?
Tyler Longren wrote: > > Here's something interesting though. There's an id field that's set to > AUTO_INCREMENT. Yep, and that's one thing I've been looking at. See, I find it strange that you need an KEY idpass (id, passcode(245)) when the ID is quaranteed to be unique in itself. Funny... Would not explain why you get more, I'd rather expect you to get fewer entries. Anyway. Try this: Drop the passcode VARCHAR and make it fixed CHAR(10). It seems like MySQL can't keep up with the speed of your inserts, and varchar is obnoxiously slow. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] For Loop Problems
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > for ($j = 0; $j < 32; $j++) { > for ($i = 0; $i < count($num_days); $i++) { > $template->addVar("room_num", "ROOM_NUM", '101'); > $template->addVar("room_type", "ROOM_TYPE", 'NQQ'); > $template->addVar("guest_NameRate", "GUEST_NAME", 'NAVID YAR'); > $template->addVar("guest_NameRate", "GUEST_ID", 'fname'); > $template->addVar("guest_NameRate", "CLASS_GUEST", 'fname'); > $template->addVar("guest_NameRate", "ROOM_RATE", '49.95'); > $template->parseTemplate("guest_NameRate", "a"); > } > $template->parseTemplate("guest_row", "a"); > } > > This inner for() loop works great. It creates a SINGLE row with 7 columns of > data (one column for each day of the week). However, the outer for() loop > does not work like it should. I want it to display 32 rows of 7 columns per > row. But what happens is that on every row after the first row it appends 7 > more columns at the end of each row. So row 2 will have 14 columns, row 3 > will have 21 columns, row 4 will have 28 columns, and so on. I can't figure > out why this is. Either it's something new in PHP5 or I'm doing something > really stupid. I am sending a PDF attachment of a snapshot showing a hint, > made purely with HTML, of what I am trying to achieve. If anyone can help me > it would be greatly appreciated. Thanks guys. I seriously doubt that php has problems to execute for loop correctly, you are probably missusing your template system. Say what does "a" stand for in: $template->parseTemplate("guest_NameRate", "a"); if it stands for append, than maybe in second pass through the loop you add 7 fiends to allready existing 7, in 3. pass you add 7 more to 14 existing, etc.. rush -- http://www.templatetamer.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] For Loop Problems
[EMAIL PROTECTED] wrote: Hello Everyone, I'm building a hotel management system and I can't seem to figure out why my for() loop doesn't work the way it should. I'm using patTemplate to create the HTML Template (I like using it and I don't want to start a pro/con template war). Here is the script: for ($j = 0; $j < 32; $j++) { for ($i = 0; $i < count($num_days); $i++) { $template->addVar("room_num", "ROOM_NUM", '101'); $template->addVar("room_type", "ROOM_TYPE", 'NQQ'); $template->addVar("guest_NameRate", "GUEST_NAME", 'NAVID YAR'); $template->addVar("guest_NameRate", "GUEST_ID", 'fname'); $template->addVar("guest_NameRate", "CLASS_GUEST", 'fname'); $template->addVar("guest_NameRate", "ROOM_RATE", '49.95'); $template->parseTemplate("guest_NameRate", "a"); } I'm not aware of what patTemplate does, but my guess is that when you addVar() each time it is just pushing each variable into an array. In other words, you keep adding 7 elements onto the end of an array WITHOUT removing old elements. There is probably a removeVar method or something similar to help you with this. If not, then you probably need to have a different template variable for each row and then populate those template variables with 1 week's data. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop and array
I think you add square brackets: so you'd have an array with a numeric key (0-n) and the value of the key would be the value of the input. or perhaps you'd prefer in this case the key of the array would be 'Hepb_ag', and the value would be true (1). In both cases, I don't think anything is set for false values... ie, if 3 out of 5 checkboxes are ticked, the array will have 3 items, not 5. Justin on 25/09/02 4:16 PM, Chris Grigor ([EMAIL PROTECTED]) wrote: > Good Morning all > > I need some help as to how to print this array, its input name is labtype > and they all have differnet values. > > Amylase > Cholesterol value='Cholesterol'> > CMV Ab IgM/G value='CMV'> > GLUCOSE - Fasting value='GLU_Fast'> > GLUCOSE - Random value='GLU_Rand'> > Hepatitus B S Ag value='Hepb_ag'> > > On the page I created if the person selects any of these then it should > submit it as name=labtype and value="whatever is selected" > > this works. > > Now upon getting this info onto my php script how would I say something like > > for each item in the array labtype, print its value? > > Any help would be really appreciated, I have had a look at a for loop trying > to use the following > > for ($a=1; $a<50; $a++) { > echo "$labtype[$a]"; > } > > but this is not working for me. Can anyone direct me in the right way ??? > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] for loop and FTP
[snip] I need to grab five pages from a web site every day and then FTP those pages to another site. I was wondering if I should grab all five pages (and store them somewhere) and then FTP all five. [/snip] This sounds like the more prudent move as it is more efficient. You can also confirm that you have received all five before establishing any FTP connection (if it would be invalid to FTP less than the full set). HTH -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] For Loop going too long
On Sat, 2002-03-30 at 15:40, David Johansen wrote: > I have a question about something weird that I've noticed Here's some code > that I have that loads up > >$sql = "SELECT * FROM pickup_times WHERE DAYOFMONTH(time0_name) = > $dayofmonth"; > >$result = mysql_query($sql, $dbh); >$day = mysql_fetch_array($result); >for ($i=0; $i echo "I: $i Result: $day[$i]"; > > When I do this it prints out 2 times the number of columns that I actually > have plus 1. All of the ones past the actual number of columns are just > empty, but is there something that I'm doing wrong? Thanks, > Dave Yup. ;) Give http://www.php.net/mysql_fetch_array a thorough beating. The function returns the results both in associatively-indexed elements and in indexed ones, so you get each one twice. Try the following and it should become clearer: $result = mysql_query($sql, $dbh); // Try both of the following lines and notice the difference. //$day = mysql_fetch_array($result); $day = mysql_fetch_array($result, MYSQL_ASSOC); foreach ($day as $colname => $value) { echo "Column name: $colname; Value: $value\n"; } Cheers! -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] For Loop going too long
Try a foreach... it works well... -Original Message- From: Lars Torben Wilson [mailto:[EMAIL PROTECTED]] On Behalf Of Lars Torben Wilson Sent: Saturday, March 30, 2002 4:38 PM To: David Johansen Cc: [EMAIL PROTECTED] Subject: Re: [PHP] For Loop going too long On Sat, 2002-03-30 at 15:40, David Johansen wrote: > I have a question about something weird that I've noticed Here's some code > that I have that loads up > >$sql = "SELECT * FROM pickup_times WHERE DAYOFMONTH(time0_name) = > $dayofmonth"; > >$result = mysql_query($sql, $dbh); >$day = mysql_fetch_array($result); >for ($i=0; $i echo "I: $i Result: $day[$i]"; > > When I do this it prints out 2 times the number of columns that I actually > have plus 1. All of the ones past the actual number of columns are just > empty, but is there something that I'm doing wrong? Thanks, > Dave Yup. ;) Give http://www.php.net/mysql_fetch_array a thorough beating. The function returns the results both in associatively-indexed elements and in indexed ones, so you get each one twice. Try the following and it should become clearer: $result = mysql_query($sql, $dbh); // Try both of the following lines and notice the difference. //$day = mysql_fetch_array($result); $day = mysql_fetch_array($result, MYSQL_ASSOC); foreach ($day as $colname => $value) { echo "Column name: $colname; Value: $value\n"; } Cheers! -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop inside a switch
I don't think it is going to work. IMO On 8/16/07, Hulf <[EMAIL PROTECTED]> wrote: > > Hi, > > switch ($q) { > > for ($i=0; $i <21; $i++) { > case 'faq$i': > echo $faq1; > break; > } > } > > > I just want to loop out a big long list of cases. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] for loop inside a switch
Hulf wrote: Hi, switch ($q) { for ($i=0; $i <21; $i++) { case 'faq$i': echo $faq1; break; } } I just want to loop out a big long list of cases. That's not a valid construct, but if I understand what you're trying do, this should work... $faqs = array(); for ($i = 0; $i < 21; $i++) $faqs[] = 'faq'.$i; if (in_array($q, $faqs)) echo $faq1; -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop inside a switch
On 8/16/07, Hulf <[EMAIL PROTECTED]> wrote: > Hi, > > switch ($q) { > > for ($i=0; $i <21; $i++) { > case 'faq$i': > echo $faq1; > break; > } > } > > > I just want to loop out a big long list of cases. Maybe you want this kind of functionality : http://www.php.net/manual/en/language.variables.variable.php $faq="faq$q"; echo $$faq; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop inside a switch
Hulf wrote: Hi, switch ($q) { for ($i=0; $i <21; $i++) { case 'faq$i': echo $faq1; break; } } I just want to loop out a big long list of cases. are the case's that you want to create with the loop going to be the only case statements in the switch? -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] for loop inside a switch
This will not work at all.. Instead of switch try with if condition as follows for ($i=0; $i <21; $i++) { if(faq$i == $q){ echo $faq1; break; } } Now it works.. You can write the code to display the result how you want.. but you cant write the code to write a code :) Cheers Warm Regards, Sanjeev http://www.sanchanworld.com http://webdirectory.sanchanworld.com - Submit your website URL http://webhosting.sanchanworld.com - Choose your best web hosting plan -Original Message- From: Hulf [mailto:[EMAIL PROTECTED] Sent: Thursday, August 16, 2007 3:11 PM To: php-general@lists.php.net Subject: [PHP] for loop inside a switch Hi, switch ($q) { for ($i=0; $i <21; $i++) { case 'faq$i': echo $faq1; break; } } I just want to loop out a big long list of cases. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop inside a switch
Sanjeev is right. You're thinking about the problem backwards. You're trying to build a Switch inside a loop. Remember, if you ever have to do some operating multiple times you're using a forloop, then the thing that you want to repeat(switch case) is INSIDE the for loop. - Dan ""Sanjeev N"" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] This will not work at all.. Instead of switch try with if condition as follows for ($i=0; $i <21; $i++) { if(faq$i == $q){ echo $faq1; break; } } Now it works.. You can write the code to display the result how you want.. but you cant write the code to write a code :) Cheers Warm Regards, Sanjeev http://www.sanchanworld.com http://webdirectory.sanchanworld.com - Submit your website URL http://webhosting.sanchanworld.com - Choose your best web hosting plan -Original Message- From: Hulf [mailto:[EMAIL PROTECTED] Sent: Thursday, August 16, 2007 3:11 PM To: php-general@lists.php.net Subject: [PHP] for loop inside a switch Hi, switch ($q) { for ($i=0; $i <21; $i++) { case 'faq$i': echo $faq1; break; } } I just want to loop out a big long list of cases. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop inside a switch
On Fri, 2007-08-31 at 15:56 -0700, Dan wrote: > Sanjeev is right. You're thinking about the problem backwards. You're > trying to build a Switch inside a loop. Remember, if you ever have to do > some operating multiple times you're using a forloop, then the thing that > you want to repeat(switch case) is INSIDE the for loop. Not always true. Sometimes once you've made the switch it applies to all members of a data array. In which case switching on every iteration is a waste of processor since you can check a single time outside the loop. Cheers, Rob. -- ... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop break and continue
Take the sample code below, paste it to a PHP file, add a real conditional, execute script. Voila, you've taken the first step towards helping yourself. Cheers, Rob. On Thu, 2003-09-25 at 11:42, Rich Fox wrote: > Hi, > Is there an equivalent to the C++ 'break' command to stop execution of a for > loop? I know I can use 'goto' but I don't want to unless I have to. > > for ($i=0; $i<$n; $i++) > if (some condition) > break; > > And, what about 'continue' which skips the rest of the code in the for loop > and immediately goes on to the next iteration? > > Thanks, > > Rich > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop break and continue
DOH! This is a new addition to PHP because it wasn't there before! Thanks for the slap. "Robert Cummings" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Take the sample code below, paste it to a PHP file, add a real > conditional, execute script. Voila, you've taken the first step towards > helping yourself. > > Cheers, > Rob. > > > On Thu, 2003-09-25 at 11:42, Rich Fox wrote: > > Hi, > > Is there an equivalent to the C++ 'break' command to stop execution of a for > > loop? I know I can use 'goto' but I don't want to unless I have to. > > > > for ($i=0; $i<$n; $i++) > > if (some condition) > > break; > > > > And, what about 'continue' which skips the rest of the code in the for loop > > and immediately goes on to the next iteration? > > > > Thanks, > > > > Rich > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- > .. > | InterJinn Application Framework - http://www.interjinn.com | > :: > | An application and templating framework for PHP. Boasting | > | a powerful, scalable system for accessing system services | > | such as forms, properties, sessions, and caches. InterJinn | > | also provides an extremely flexible architecture for | > | creating re-usable components quickly and easily. | > `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop break and continue
On Thu, 2003-09-25 at 12:04, Rich Fox wrote: > DOH! > > This is a new addition to PHP because it wasn't there before! > > Thanks for the slap. PHP has supported break for as long as I can remember which goes back to about 1999 and PHP 3.something. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop break and continue
Can't you let me have a shred of programming self-respect? Rich (I should have cracked the book) Fox > On Thu, 2003-09-25 at 12:04, Rich Fox wrote: > > DOH! > > > > This is a new addition to PHP because it wasn't there before! > > > > Thanks for the slap. > > PHP has supported break for as long as I can remember which goes back to > about 1999 and PHP 3.something. > > Cheers, > Rob. > > -- > .. > | InterJinn Application Framework - http://www.interjinn.com | > :: > | An application and templating framework for PHP. Boasting | > | a powerful, scalable system for accessing system services | > | such as forms, properties, sessions, and caches. InterJinn | > | also provides an extremely flexible architecture for | > | creating re-usable components quickly and easily. | > `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] for loop break and continue
[snip] Can't you let me have a shred of programming self-respect? Rich (I should have cracked the book) Fox [/snip] Nah, too easy! :) We all get bumped from time to time -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] for loop break and continue
> Can't you let me have a shred of programming self-respect? > > Rich (I should have cracked the book) Fox Get out! No soup (or respect) for you! ;) Edward Dudlik Becoming Digital www.becomingdigital.com - Original Message - From: "Rich Fox" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, 25 September, 2003 12:26 Subject: Re: [PHP] for loop break and continue Can't you let me have a shred of programming self-respect? Rich (I should have cracked the book) Fox > On Thu, 2003-09-25 at 12:04, Rich Fox wrote: > > DOH! > > > > This is a new addition to PHP because it wasn't there before! > > > > Thanks for the slap. > > PHP has supported break for as long as I can remember which goes back to > about 1999 and PHP 3.something. > > Cheers, > Rob. > > -- > .. > | InterJinn Application Framework - http://www.interjinn.com | > :: > | An application and templating framework for PHP. Boasting | > | a powerful, scalable system for accessing system services | > | such as forms, properties, sessions, and caches. InterJinn | > | also provides an extremely flexible architecture for | > | creating re-usable components quickly and easily. | > `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php