Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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.

Reply With Quote
  #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"?
Reply With Quote
  #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.


Reply With Quote
  #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.
Reply With Quote
  #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.


Reply With Quote
  #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.
Reply With Quote
  #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....

Reply With Quote
  #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.
Reply With Quote
  #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..........

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:47 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.