Come on, you know you want to buy me a beer!

Ok, really easy example of a while loop counter.

The script requires 2 variables:
1) What number to start on?
2) What number to end on?

Take a look...

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
$count_up_to
=50;
$count_from=0;

// fix the offset
$count_up_to $count_up_to 1;
$i $count_from;

while (
$i <= $count_up_to) {
    
// increase the current value
    
$i $i 1;
    
    echo 
"Line : ".$i;
    echo 
"<br />";
}
?>

This gives you (not surprisingly) :

Line : 1
Line : 2
Line : 3
Line : 4...

--- I won't list them all. You get the idea.

...Line : 47
Line : 48
Line : 49
Line : 50

This is all fine and dandy, but this is where it all comes together.

Imagine what can be done in that loop! You could automate a number of tasks to run, or maybe put a send mail script in between them. ** don't actually try the mail() thing. Spammers are bad!!

Back in the day when email was relatively un-checked still, I once flooded a friends inbox with 500 emails.

He wasn't impressed :(

Comments


Your Name:

Email Address: (won't be published)

Comments: (no HTML allowed)

 

There are no comments yet.

 

 

 

 

 

 

Latest Posts