I'm working on a piece of php in the hopes that it will call data from an SQL table, group any data that has a matching value in a particular field(not the primary field), and then assign the rest of the field values to those groups and call them as one image for each group, based on whichever data in each group has the lowest primary field. Its important that the data for the rest of the fields is not "merged" with the grouping(probably group by) so I'm thinking two db queries might be in order.
So a table like this
Item Value Field3 Field4
1 2 name1
2 2 name2
3 1 name3
4 3 name4
5 1 name5
would initially be grouped into 3 sections(1, 2 and 3 based on the values), and then the names for each item and any other field data would be called and sorted into the right group(but not merged!), and then an image would be assigned for each group with something l like src="root_path/images/' . $item . '.png'; for the first value only in each group. So item 3, 1 and 4 would be the respective images created. Here is what I have so far, please help, I really have no idea what I'm doing.
for ($i=0; $i < 10; $i++)
{
$value = $i;
$sql = 'SELECT item, value
FROM ' . ITEMS_TABLE . '
WHERE value = $value[$i]
GROUP BY value';
$db->sql_freeresult($result);
$data = $row['value'];
$item = $row['item'];//does this row even exist anymore after being grouped?
//for now I'll assume it does.
if ($data)//somehow assign it to first in group?
{
$src= 'root_path/images/' . $item . '.png';
}
else//for items NOT the first in group... maybe another if conditional here?
{
$subsrc = 'root_path/images/' . $item . '.png';
}
$sql = 'SELECT item, field3, value, field4
FROM ' . ITEMS_TABLE . '
WHERE value = $value[$i]';
$template->assign_block_vars('items', array(
'NAME'=> $row['field3'],
'DESCRIPTION'=> $row['field4'],
'ITEM'=> $row['item'],
'IMAGE' => $src,
'SUBIMG' => $subsrc,
);
I'm trying to display a dropdown menu for all items with associated values(with only one image), if that makes visualizing a practical use for this code easier. So multiple items, with only one image that onclick will display the rest for every group(I'll deal with the necessary js/css for that later). So the code above is obviously only halfway there, and I need some pointers to get it where it needs to be. Please help.
} //forgot to close the for loop.
So a table like this
Item Value Field3 Field4
1 2 name1
2 2 name2
3 1 name3
4 3 name4
5 1 name5
would initially be grouped into 3 sections(1, 2 and 3 based on the values), and then the names for each item and any other field data would be called and sorted into the right group(but not merged!), and then an image would be assigned for each group with something l like src="root_path/images/' . $item . '.png'; for the first value only in each group. So item 3, 1 and 4 would be the respective images created. Here is what I have so far, please help, I really have no idea what I'm doing.
for ($i=0; $i < 10; $i++)
{
$value = $i;
$sql = 'SELECT item, value
FROM ' . ITEMS_TABLE . '
WHERE value = $value[$i]
GROUP BY value';
$db->sql_freeresult($result);
$data = $row['value'];
$item = $row['item'];//does this row even exist anymore after being grouped?
//for now I'll assume it does.
if ($data)//somehow assign it to first in group?
{
$src= 'root_path/images/' . $item . '.png';
}
else//for items NOT the first in group... maybe another if conditional here?
{
$subsrc = 'root_path/images/' . $item . '.png';
}
$sql = 'SELECT item, field3, value, field4
FROM ' . ITEMS_TABLE . '
WHERE value = $value[$i]';
$template->assign_block_vars('items', array(
'NAME'=> $row['field3'],
'DESCRIPTION'=> $row['field4'],
'ITEM'=> $row['item'],
'IMAGE' => $src,
'SUBIMG' => $subsrc,
);
I'm trying to display a dropdown menu for all items with associated values(with only one image), if that makes visualizing a practical use for this code easier. So multiple items, with only one image that onclick will display the rest for every group(I'll deal with the necessary js/css for that later). So the code above is obviously only halfway there, and I need some pointers to get it where it needs to be. Please help.
} //forgot to close the for loop.