Table for PHP Downloads

Asked

Viewed 227 times

2

I’m creating a system in PHP download digital products, I will explain briefly:

  1. User enters the site, right on the home page, will have some products to download.
  2. He registers and buys the product.
  3. The product should be listed for it in the My Downloads in your profile.

My question is, how do I check the downloads that this user has available in my database?

More specifically:

I have the following table called downloads:

ID | NOME | DESCRIÇÃO | VERSÃO

I was thinking of creating a column in the user table, where will list all the download ids that this user has, but is that possible? If not, what would you do?

  • puts an extra field in the table with the permissible value, e.g.: 1-normal user; 2-vip user, etc. Ai at the time of pulling from the database, just check the user and product/file perm

  • But in this way the user would have access to all products, what I need is an individual permission for each product.

  • save the product id’s and the user id in another table, use the table join in SQL, ai just query by this table and display, type, when the user buys such product, save in the table the id of it, and the product

  • That is, I must create a new table "purchases", in this table I must save the user ID and the plugin ID and then I do a foreach on?

  • but not necessarily need to use the foreach, just consult in the BD, and dps with a while(); tbm da para fazer,

1 answer

0

"I was thinking of creating a column in the user table, where it will list all the download ids that this user has, but Is that possible? If not, what would you do?"

I don’t think it works, because then each user will only have available a DOWNLOAD for it, since the column ID_DOWNLOAD will store only one ID for downloads per user column. The right way is to create a third USUARIOS_DOWNLOADS table with the columns ID_USUARIO and ID_DOWNLOAD.

Thus, the logic of the tables will be: table DOWNLOADS: registration of products; table USER: registration of customers who will consume their products; and table USUARIO_DOWNLOADS: register which downloads will relate with which users. Example:

[Legend] Table : fields=values
users: ID=100; NAME=JOSÉ; // ID=150; NAME=DANILO;
downloads: ID=501; NAME=C#COURSE; // ID=502; NAME=C++ COURSE; // ID=503; NAME=JAVA COURSE;
usuarios_downloads : ID_USUARIO=100; ID_DOWNLOAD=501; // ID_USUARIO=100; ID_DOWNLOAD=502; // ID_USUARIO=150; ID_DOWNLOAD=503;

For the above example, JOSÉ (id=100) has a link to the C# and C++ courses (id=501 and id=502), and DANILO (id=150) has access to the JAVA course link (id=503).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.