Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.www.php > #21964

Re: User che veda uno o più brand

From Alessandro Pellizzari <shuriken@amiran.it>
Newsgroups it.comp.www.php
Subject Re: User che veda uno o più brand
Date 2018-04-08 16:38 +0100
Message-ID <fiurb9Fns6pU1@mid.individual.net> (permalink)
References <pab70n$3nm$1@virtdiesel.mng.cu.mi.it> <fiso66F9rhqU1@mid.individual.net> <pad30m$87r$1@virtdiesel.mng.cu.mi.it>

Show all headers | View raw


On 08/04/18 13:47, GabrieleMax wrote:

>> create table user (id primary key, ...)
>> create table brand (id primary key, ...)
>> create table user_brand (user_id int, brand_id int)
> 
> Nella tabella user dovrei creare tanti utenti quanti sono i marchi 
> presenti nella tabella brand e collegarli tra loro con le FK in un 
> rapporto di 1:1?
> 
> Nella tabella user_brand dovrei creare l'utente "vero e proprio" per il 
> login ma ad esempio l'utente "X" in questa tabella come può essere 
> associato a più utenti che potremmo definire "A" "B" e "C" contenuti 
> nella tabella user visto che, come già accennato, l'utente "X" potrebbe 
> vedere non solo "A" ma anche "B", "C", etc.

No. Nella tabella user metti tutti i dati degli utenti. Nella tabella
brand metti tutti quelli dei brand.

Nella tabella user_brand metti sono l'id dell'utente e quello del brand
a cui vuoi associarlo.

Vuoi tutti i brand di un utente (dato un $userId)?

select b.* from user_brand ub join brand b on ub.brand_id=b.id where
ub.user_id=$userId

Vuoi tutti gli utenti associati a un brand (dato un $brandID)?

select u.* from user_brand ub join user u on ub.user_id=u.id where
ub.brand_id=$brandId

Bye.

Back to it.comp.www.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

User che veda uno o più brand GabrieleMax <gabriele1NOSPAM@hotmail.com> - 2018-04-07 21:43 +0200
  Re: User che veda uno o più brand Alessandro Pellizzari <shuriken@amiran.it> - 2018-04-07 21:32 +0100
    Re: User che veda uno o più brand GabrieleMax <gabriele1NOSPAM@hotmail.com> - 2018-04-08 14:47 +0200
      Re: User che veda uno o più brand Alessandro Pellizzari <shuriken@amiran.it> - 2018-04-08 16:38 +0100
        Re: User che veda uno o più brand GabrieleMax <gabriele1NOSPAM@hotmail.com> - 2018-04-08 22:57 +0200
          Re: User che veda uno o più brand Alessandro Pellizzari <shuriken@amiran.it> - 2018-04-09 15:36 +0100
            Re: User che veda uno o più brand GabrieleMax <gabriele1NOSPAM@hotmail.com> - 2018-04-09 22:06 +0200
    Re: User che veda uno o più brand fmassei@gmail.com - 2018-04-08 08:55 -0700

csiph-web