how to put the 0-100 numbers into 1.txt and 100-200 into 2.txt ?

Discussion in 'PHP' started by w47w47, Oct 28, 2009.

  1. #1
    how to put the 0-100 numbers into 1.txt and 100-200 into 2.txt and so on 200-300 into file 3.txt ?

    in PHP of course.

    i don't know if i'm really that dumb or is it the 36 hours of no sleep that i can't figure it out. :S
     
    w47w47, Oct 28, 2009 IP
  2. w47w47

    w47w47 Peon

    Messages:
    255
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ok, i figured it out. ;) just a little if statement :p if the number is bigger then 100 then add to 1.txt else 2.txt damn... can't belive i couldn't figure out that. :D just too tired i think. :S
     
    w47w47, Oct 28, 2009 IP
  3. tonythetiger

    tonythetiger Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thats one way to do it but what happens when you get into 600 - 700 and so forth, you are going to have to keep adding else if, else if, etc... which is not a scalable solution. look into modular(%) operand. for example
    $loop = 1;
    $fileIter = 1;
    while($loop < 1000){

    if(($loop%100) == 0)
    ++$fileIter;

    put data into $fileIter.'txt';

    ++$loop;
    }

    sorry for the pseudo code, but i think you can catch my drift.
     
    tonythetiger, Oct 28, 2009 IP