Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.www.php > #22648
| From | ^Bart <gabriele1NOSPAM@hotmail.com> |
|---|---|
| Newsgroups | it.comp.www.php |
| Subject | Re: [OT] MySQL/MariaDB db per gusti utenti |
| Date | 2019-04-22 19:13 +0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <q9ksng$ml3$1@gioia.aioe.org> (permalink) |
| References | <q9i9g9$1i7b$1@gioia.aioe.org> <gi5gahF2ut7U1@mid.individual.net> <q9kohh$3g1$1@gioia.aioe.org> <gi683eF802jU1@mid.individual.net> |
> renderlo indipendente, ma per ora ti consiglio di concentrarti su SQL e
> non pensarci troppo.
Credo anch'io sia la soluzione migliore!
> create table ingredients (
> id int, -- NB: no primary key
> lang int,
> name
> foreign key fk_lang(lang) references languages(id),
> primary key (id, lang)
> )
>
> Hai la rogna di dover generare a mano un nuovo "id" quando crei un nuovo
> ingrediente, ma la tabella diventa qualcosa tipo:
Ho capito il tipo di rogna... diciamo che basterebbe fare
"semplicemente" attenzione durante l'inserimento dei dati attenzione che
bisognerebbe porre anche se il collegamento fosse stato legato con una FK!
Però quando si dovessero aggiungere almeno una decina di lingue volendo
scegliere quella inglese come quella principale dovrei fare un filtro
specifico per tirarmi fuori tutti gli id ed associarli alle nuove lingue.
> Quindi il latte avrà sempre id 1 in tutte le lingue, e costruire le
> query sarà più semplice, oltre a non dover avere un'asplosione algebrica
> di righe nella tabella users (ricorda che è n:m, quindi ti serve una
> tabella di collegamento):
Chiarissimo, da un'altra parte mi hanno suggerito, credo, la stessa
cosa; nell'esempio citato c'è un ingrediente milk che esiste in entrambe
le lingue mentre chi mi ha risposto ha supposto che ci potessero essere
due ingredienti senza traduzione in inglese come boter (butter) e eieren
(eggs).
Add a language_id to every table that has descriptions
so for Inredients:
ingredients
-------------------
id | language | name
-------------------
1 | 0 | milk
2 | 0 | spelt
3 | 0 | onion
Also define a 'default' language (i did choose to make '0' the default
language)
Other languages can be added (i.e. 1='Dutch')
1 | 1 | melk
4 | 1 | boter
5 | 1 | eieren
This can, of course, be 'beautified' with a foreign key, so you can only
create a dutch translation for an ingredient which has an English text.
SELECT ingredient.name
from ingredients, users
where id=3 and language_id = users.language_id
order by language_id desc
limit 1
This should give description in language of user, and when the
description in the language of the user does not exist it will show the
default ('0') description.
> Bye.
Saluti.
^Bart
Back to it.comp.www.php | Previous | Next — Previous in thread | Find similar | Unroll thread
[OT] MySQL/MariaDB db per gusti utenti ^Bart <gabriele1NOSPAM@hotmail.com> - 2019-04-21 19:32 +0200
Re: [OT] MySQL/MariaDB db per gusti utenti Alessandro Pellizzari <shuriken@amiran.it> - 2019-04-22 10:37 +0100
Re: [OT] MySQL/MariaDB db per gusti utenti ^Bart <gabriele1NOSPAM@hotmail.com> - 2019-04-22 18:01 +0200
Re: [OT] MySQL/MariaDB db per gusti utenti Alessandro Pellizzari <shuriken@amiran.it> - 2019-04-22 17:23 +0100
Re: [OT] MySQL/MariaDB db per gusti utenti ^Bart <gabriele1NOSPAM@hotmail.com> - 2019-04-22 19:13 +0200
csiph-web