I have two tables, items and itemmeta. items has item_id which links it to itemmeta which has itemmeta_id, item_id, meta_key and meta_value. I did this so if i needed to add a special flag or value to an item i didn't have to keep changing the items table.
Now i am paying the price for flexibility. I want to know if i can combine a query and some php into a better designed query.
first i do something like this:
SELECT * FROM items;
then while looping through those i do this for each in php:
$sql = "SELECT * FROM itemmeta WHERE item_id='".$item['item_id']."' ";
$meta_result = mysql_query($sql, $conn) or die(mysql_error());
$item['meta'] = array();
while( $meta=mysql_fetch_assoc($meta_result) ) {
$item['meta'][$meta['meta_key']] = $meta['meta_value'];
}
Is it possible to do the second part using a subquery or something like that? i think the hard part would be keeping the same output. ex: $item['meta']['my_key'] = 'value'. I assume it would be more $item['meta'][0][0] = 'my_key' and $item['meta'][0][1] = 'value'.