Hi Everyone, I have the following php calulation

    $tplaunch = $tplaunch - $tpsold;

This calculates as you would expect.
I am helping to build a website that offers the first 25 members to purchase a product at a reduced cost.
tplaunch is the number of user who will get the discount, once they have sold more than tplaunch the price will change.

They want to reflect how members can purchase the product at a discount, But the above calculation returns -1 if I enter 26 sales into the database.

How can I make this say 0

Thanks in advance.

Recommended Answers

All 2 Replies

You could use max() to set a bottom limit of 0.

$tplaunch = max(0,($tplaunch - $tpsold));

@traevel, thanks very much for your reply, I didnt know about using max()
Great stuff...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.