2 Replies - 450 Views - Last Post: 19 March 2009 - 12:33 PM Rate Topic: -----

#1 skirkpatrick  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 18-February 08

Incremental issue

Posted 19 March 2009 - 11:25 AM

I am trying to increment a numbering scheme and end with a specific number.

The scenario:
I work for a printing company and we need to injet numbers on printed forms, in order to do that we need to give the operators enough product to overlap. I need the last number in the stream to be a specific number in relation to the stream.

 
$startnumber = 1;
$endingnumber = 500;
$reset = 15;
$run = 100;
//$end is the number I need to be the last displayed
$end = 1+500+15-1;
$i = $startingnumber;
while ($i <= $endingnumber)
{
	$i=$i-$reset;
	echo $i;
	$i=$i+$run+$reset;
	echo "--------->" . $i . "<BR>";   
}
echo "<BR> \t" . $end; 


What I am getting:

-15--------->100
85--------->200
185--------->300
285--------->400
385--------->500
485--------->600

515

What I need:

-15--------->100
85--------->200
185--------->300
285--------->400
385--------->500
485--------->515

515

I don't know if this makes sense or not

Steve

Is This A Good Question/Topic? 0
  • +

Replies To: Incremental issue

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5881
  • View blog
  • Posts: 12,758
  • Joined: 16-October 07

Re: Incremental issue

Posted 19 March 2009 - 11:37 AM

View Postskirkpatrick, on 19 Mar, 2009 - 12:25 PM, said:

I don't know if this makes sense or not


Not particularly, no. :P

Right, you have this: "$i=$i+$run+$reset;" which is essentially this "$i += 115;". So, when you start at 485, you add 115, and you jump over your target number?

So, in your program, you should simply check to see if you've exceeded your target number. If you have, make the current number equal the target number. Do this before you print but after you evaluate and you'll be fine.
Was This Post Helpful? 1

#3 skirkpatrick  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 18-February 08

Re: Incremental issue

Posted 19 March 2009 - 12:33 PM

That worked - Thanks

Added an if/else in front of the while
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1