Question

Lets say we have this MySQL table

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

Given these database entries, is there a way to retrieve this values as to get it in the format below? Or is my database modeling wrong?

array(
   [author] => array(Sabriel Armstrong,Peter Abhorsen, Garth Stein),
   [item] => array(bell,book,sword, wand)
)
Was it helpful?

Solution

MySQL does not have arrays so it's hard to figure out what exact result set you are expecting. In any case, your DB design provides no way to match an author with an item: such information is simply not stored anywhere.

I suppose you'll have a reason to avoid this:

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

:-?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top