1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need to generate numbers 1-1000000 in a list

Discussion in 'PHP & Perl' started by coxi999, Apr 6, 2011.

  1. coxi999

    coxi999 Junior Member

    Joined:
    Aug 14, 2007
    Messages:
    167
    Likes Received:
    49
    Location:
    UK
    I need to generate numbers 1 - 1000000 in a list format

    1
    2
    3
    4
    5
    6
    etc

    I found this php code to do something similar but it puts the numbers like this

    1,2,3,4,5,6,7,etc

    Code:
    <?php
     $lowestnum = 1;
     $highestnum = 1000000;
     
    for($i=$lowestnum; $i<=$highestnum; $i++){
     echo "$i, ";
     }
     ?>
    Could someone please give edit this code for me to put the numbers in list format. Usless at PHP :)
     
  2. altschule

    altschule Regular Member

    Joined:
    Sep 1, 2010
    Messages:
    282
    Likes Received:
    185
    Location:
    Sector 9
    PHP:
    <?php
     $lowestnum 
    1;
     
    $highestnum 1000000;
     
    for(
    $i=$lowestnum$i<=$highestnum$i++){
     echo 
    "$i<br />";
     }
     
    ?>
    Just replaced the ', ' with '<br />' which is the HTML for a linebreak. Enjoy
     
    • Thanks Thanks x 1
  3. coxi999

    coxi999 Junior Member

    Joined:
    Aug 14, 2007
    Messages:
    167
    Likes Received:
    49
    Location:
    UK
    arr right, that simpe great, thanks alot..
     
  4. coxi999

    coxi999 Junior Member

    Joined:
    Aug 14, 2007
    Messages:
    167
    Likes Received:
    49
    Location:
    UK
    Is it possible to edit this code so i can add a prefix to each number?

    number1
    number2
    number3
    etc?????
     
  5. artizhay

    artizhay BANNED BANNED

    Joined:
    Nov 21, 2010
    Messages:
    1,867
    Likes Received:
    1,335
    Replace $i with your prefix + $i.
    So: number$i would produce number1, etc.
     
  6. Autumn

    Autumn Elite Member

    Joined:
    Nov 18, 2010
    Messages:
    2,197
    Likes Received:
    3,041
    Occupation:
    I figure out ways to make money online and then au
    Location:
    Spamville
    Cleaner: edit the value of $prefix

    PHP:
    <?php
     $prefix 
    'my prefix ';
     
    $lowestnum 1;
     
    $highestnum 1000000;
     
    for(
    $i=$lowestnum$i<=$highestnum$i++){
        echo 
    "$prefix$i<br />";
    }
    ?>
     
  7. altschule

    altschule Regular Member

    Joined:
    Sep 1, 2010
    Messages:
    282
    Likes Received:
    185
    Location:
    Sector 9
    You can output anything you want. Echo is just that, it displays to the browser what you "ECHO". Anything with a Dollar sign ($) in front of it is a variable.
    PHP:
    <?php echo "Hello World"?>
    would display hello world... etc.
    PHP:
    <?php 
     $prefix 
    'my prefix ';
     
    $postfix '<br />';
     
    $lowestnum 1
     
    $highestnum 1000000
      
    for(
    $i=$lowestnum$i<=$highestnum$i++){ 
        echo 
    $prefix.$i.$postfix

    ?>
    is how I'd do it
    PHP:
    http://php.net/echo