Table for Downloads in PHP

2

I'm creating a system in PHP to download digital products, I'll briefly explain:

  • User enters the site, right on the homepage, will have some products to download.
  • He signs up and buys the product.
  • The product should be listed for it in the My Downloads section of your profile.
  • My question is, how will I check the downloads that this user has available in my database?

    More specifically:

    I have the following table named downloads:

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

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

        
    asked by anonymous 04.11.2017 / 00:39

    1 answer

    0
      

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

    I do not think it works, since each user will only have DOWNLOAD available for him since the ID_DOWNLOAD column will store only one ID per column per user. The right way is for you to create a third USER_DOWNLOADS table with the USER_ID and ID_DOWNLOAD columns.

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

    [Caption] Table: fields = values
    users: ID = 100; NAME = JOSÉ; // ID = 150; NAME = DANILO; Home downloads: ID = 501; NAME = C # COURSE; // ID = 502; NAME = C ++ COURSE; // ID = 503; NAME = JAVA COURSE; Home users_downloads: USER_ID = 100; ID_DOWNLOAD = 501; // USER ID = 100; ID_DOWNLOAD = 502; // USER ID = 150; ID_DOWNLOAD = 503;

    By 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).

        
    04.11.2017 / 03:28