SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: help with query

  1. #1
    SitePoint Addict Smolf3d's Avatar
    Join Date
    Aug 2004
    Location
    russia
    Posts
    224
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post help with query

    Code MySQL:
    CREATE TABLE `conf_discount` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `discount` varchar(100) NOT NULL,
      `money` varchar(100) NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=cp1251;
     
    INSERT INTO `conf_discount` VALUES (1, '2', '500000');
    INSERT INTO `conf_discount` VALUES (2, '5', '1000000');
    INSERT INTO `conf_discount` VALUES (3, '7', '5000000');
    INSERT INTO `conf_discount` VALUES (4, '10', '10000000');

    And another table with ORDERS

    Code MySQL:
    CREATE TABLE `orders` (
       .....................
      `pay_sum` int(10) NOT NULL,
    ) ENGINE=MyISAM;


    Now i need to do query, so if Sum(pay_sum) > or = one of discount money print discount.

    Like

    Code PHP:
    $paysum = 604180;
    if($paysum >= $discount['money']){
    print("".$discount['discount']."%"); 
    }else{
    print("0%");
    }


    thanks and sorry for my little english.

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Use your query to find this information for you.

    What i assume you're trying to do (and correct me if i'm wrong!) is store it so that if a person's order is more than X dollars/pounds/spacebucks/whatever, they get Y% discount.

    I assume you're putting this information into a database because you want to be able to modify it through the GUI elsewhere, which is fine.

    So lets use the database a little better.

    Add a new record to your discount table which has discount 0, money 0.

    Now,
    Code MySQL:
    SELECT discount 
    FROM conf_discount 
    WHERE money <= $paysum 
    ORDER BY money DESC 
    LIMIT 1;
    (You may want/need to get more fancy with this if you're trying to pull multiple records; additionally, if this display already has a record in the 'order' table, you may want to combine the two queries)

    This will return a record with only the information you care about; the discount percent.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Addict Smolf3d's Avatar
    Join Date
    Aug 2004
    Location
    russia
    Posts
    224
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thanks for idea.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •