on Sun, 22 Sep 2002 17:06:01 GMT, Mariusz wrote:

> I have a "discount" table that carries percentage discounts that
> should be looked up when the customer submits a discount code and
> taken into calculation of the total price. My table looks something
> like this: 
> 
> field names:    |senior|student|...
> values:            |0.20|0.50|...

This is bad design. What you want is one table with two fields, like e.g. 
(untested):

    CREATE TABLE discounts (
        discounttype   CHAR(20) NOT NULL PRIMARY KEY,
        discountvalue  FLOAT
    );

in which you store the following records:

    INSERT INTO discounts VALUES ('senior',  0.20);
    INSERT INTO discounts VALUES ('student', 0.50);
    # ...

Then you say:

  
    my ($d) = $sth->selectrow_array(qq{

        SELECT 
            discountvalue 
        FROM discounts 
        WHERE 
            discounttype = ?

    }, undef, $user_supplied_type);

    if (defined $d) {
        # $user_supplied_type is in database
    } else {
        # $user_supplied_type is not in database
    }

    # ....

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to