 |
| 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
|
|
|
|

July 21st, 2004, 01:46 AM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

July 21st, 2004, 10:31 PM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
you mean something like "do IncrementNumber while NumberHasNotReached100"?
|
|

July 22nd, 2004, 01:17 AM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hmmmmm.............I think something like this.
|
|

July 22nd, 2004, 03:50 PM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

July 22nd, 2004, 09:00 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

July 23rd, 2004, 06:30 PM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

July 25th, 2004, 07:40 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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....
|
|

July 27th, 2004, 12:26 PM
|
|
Authorized User
|
|
Join Date: Jun 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

July 28th, 2004, 02:58 AM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
Thanks..........
|
|
 |