automated query for multiple promo codes

Discussion in 'Databases' started by kabucek, Apr 23, 2009.

  1. #1
    hello,

    I have this query for creating one code at a time

    INSERT INTO `database1`.`table1` (
    `couponCode`,
    `pageCount`
    )
    VALUES (
    'promo-001002', '2'
    );

    but this will create only one code.
    I need a query that will create 200 codes with starting number "-001002".
    Is there a way to do it?

    Thanks
     
    kabucek, Apr 23, 2009 IP
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    maybe doing a loop?
     
    crivion, Apr 24, 2009 IP
  3. nayes84

    nayes84 Member

    Messages:
    34
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    you will need to use some coding in php language or whatever
    example:
    
    for($i=1002;$i<1202;$i++)
    {
    	mysql_query("INSERT INTO `database1`.`table1` (
    `couponCode`,`pageCount`) VALUES ('promo-00" . $i . "', '2');");
    }
    
    PHP:
     
    nayes84, Apr 24, 2009 IP
  4. pitagora

    pitagora Peon

    Messages:
    247
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you codes are easy to guess. At least make sure you don't allow multiple coupons on the same transaction or you'll end up like others selling stuff for 0$
     
    pitagora, Apr 27, 2009 IP