Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 21st, 2004, 01:46 AM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default Do Loop

Hi, I want the system can loop many time and store the data in database each time I press a submit button.
i.e:

Let say the quantity componet = 100, each have differrent serial number. Then I want the system can loop 100 times and generate continually serial number from the begin number (1st serial number I create then system continue....)and store the records in database. Because I don't need to insert the record one by one until 100 times!!

The problem is how I do it? Please. :(

Thanks in advance,
molly.

  #2 (permalink)  
Old July 21st, 2004, 10:31 PM
Authorized User
 
Join Date: Jun 2004
Location: Oslo, , Norway.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you mean something like "do IncrementNumber while NumberHasNotReached100"?
  #3 (permalink)  
Old July 22nd, 2004, 01:17 AM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Hmmmmm.............I think something like this.


  #4 (permalink)  
Old July 22nd, 2004, 03:50 PM
Authorized User
 
Join Date: Jun 2004
Location: Oslo, , Norway.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the loop itself could look like this:
for($counter=0; $counter<100; $counter++)
  {
  functionThatGeneratesSerialNumber();
  functionThatInsertsSerialIntoDatabase();
  }


as you can see, at the start the counter is set to 0, but with every iteration it'll be incremented by one, so after the first run it'll be set to 1, after the second run it'll be 2, and so on until it reaches 100.
for every iteration it'll run the code between the { brackets } .

you can take that loop and just replace the two functions with your own functions or code that does what you want to get done.
  #5 (permalink)  
Old July 22nd, 2004, 09:00 PM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Quote:
quote:the loop itself could look like this:
for($counter=0; $counter<100; $counter++)
it counter start from 1 and until reaches 100... but not like I want.

I want itself can counter start from the number I insert in and reach until the finish number i select. So, it dynamic. I have testing my script, the number can loop itself but I still need press a button many times to store each record in dbase.

Quote:
quote:
{
functionThatGeneratesSerialNumber();
functionThatInsertsSerialIntoDatabase();
}
you can take that loop and just replace the two functions with your own functions or code that does what you want to get done.
PHP language still new for me. So, I almost not using Function in my script. Because I don't know how to use it.

Is it possible to do?

Thanks in advance,
molly.


  #6 (permalink)  
Old July 23rd, 2004, 06:30 PM
Authorized User
 
Join Date: Jun 2004
Location: Oslo, , Norway.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this here might be more to your liking:

$startAt = aNumberOfYourChoice;
$endAt = anotherNumberOfYourChoice;

for($counter = $startAt; $counter < $endAt; $counter++)
{
codeToGenerateSerial;
codeToAccessDB;
}


the little snippet above should provide you with a means to iterate through the loop without having to press a button for every time it goes to the db.
  #7 (permalink)  
Old July 25th, 2004, 07:40 PM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Hi,
This is my script to create the serial number, but I don't know how to replace it. Can you please help me?

Attach code:
if ($lot_qty < $qty)
{ $s1++ ;
    $qty--;

}
elseif ($lot_qty == $qty)
{
    echo "<br>";
    echo "";
    echo "<b><p><h2>Add Finish!!</h2></p></b>";
    echo " </b>";

}
else
{
    echo "<br>";
    echo "";
    echo "<b><p><h2>Done!</h2></p></b>";
    echo " </b>";
}

Quote:
quote:
$startAt = aNumberOfYourChoice;
$endAt = anotherNumberOfYourChoice;

for($counter = $startat; $counter < $endAt; $counter++)
{
codeToGenerateSerial;
codeToAccessDB;
}
Thanks in advance....

  #8 (permalink)  
Old July 27th, 2004, 12:26 PM
Authorized User
 
Join Date: Jun 2004
Location: Oslo, , Norway.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well, if that script works to create a serial, then you can just put it inside the for() loop in place of the codeToGenerateSerial; line.

grimmy
God, grant me the serenity to accept the things I cannot change, the courage to change the things I can, and the wisdom to hide the bodies of those people I had to kill because they pissed me off.
  #9 (permalink)  
Old July 28th, 2004, 02:58 AM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Hi,

Thanks..........



Similar Threads
Thread Thread Starter Forum Replies Last Post
Do Loop stealthdevil Access VBA 5 October 5th, 2006 01:22 PM
Help with for-each loop athanatos XSLT 0 April 10th, 2006 07:20 PM
Do Until loop with IF crmpicco Classic ASP Databases 2 June 15th, 2005 05:35 PM
For....Loop kliu9 Excel VBA 5 February 10th, 2005 06:43 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.