Skip to content
Advertisement

What is the simplest way of implementing pricing plans in mysql and php?

I am working on a project, and I am trying to find a way to associate my pricing plans table with a customer.

JavaScript

My first thought was to add the plan id as foreign key to the customers table. But i also need to know when is the expire date (based on the purchase date and the days of the plan selected).

Advertisement

Answer

When attempting to do something like this, it is best to keep tables abstracted from each other.

JavaScript

following an approach like this will allow you alter this table if needed to add extra information. you could also follow a similar approach in the future with another table.

the key to all of this is separating your concerns ( the data ) into separate containers.

Edit: to kind of hint at what I’m getting at about why separating the tables is a good idea, I added the date_purchased as a field in the user_pricing_plans table.

a dba I know once said that “mysql is not a place for developers – they try to create tables to work with their code. tables are meant to represent data. your code should be written to work with the data and the schemas that represent them – not the other way around”

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement