Domanda

Consente di dire che abbiamo questa tabella di MySQL

name       value
author     Sabriel Armstrong
author     Peter Abhorsen
author     Garth Stein
item       bell
item       book
item       sword
item       wand

Alla luce di queste voci di database, c'è un modo per recuperare questi valori da ottenere nel formato di seguito? O è la mia modellazione di database che non va?

array(
   [author] => array(Sabriel Armstrong,Peter Abhorsen, Garth Stein),
   [item] => array(bell,book,sword, wand)
)
È stato utile?

Soluzione

MySQL non ha matrici, quindi è difficile capire che cosa esattamente set di risultati vi aspettate. In ogni caso, il vostro disegno DB fornisce alcun modo per abbinare un autore con un elemento: tali informazioni non viene semplicemente memorizzato ovunque

.

Immagino avrete un motivo per evitare questo:

author            item
======            ======
Sabriel Armstrong bell
Peter Abhorsen    book

: -?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top