Hi, Thanks Tim, that is actually a great solution for the specific problem.
On Thu, Feb 19, 2009 at 11:32 AM, Aaron Cooper <[email protected]>wrote: > At a quick glance without any planning or knowing a whole lot about > joomla, I'd be inclined to make Classes for > #__vm_product_selecon_product_codes and #__vm_product set > custom_attribute in this case. > > That way, the code could look more like this when used: > > // New usage code - The reusable part > $myCodes = new vm_product_selecon_product_codes(); > $list = $myCodes->getAll(); > > $myProductAttributes = new vm_product set custom_attribute() > $myProductAttributes->updateAttributes($list); > > > > // getAll() method code > $db =& JFactory::getDBO(); > $sql = 'select product_id, product_sku from > #__vm_product_selecon_product_codes '. > 'order by product_id, product_sku '; > $db->setQuery($sql); > > $list = $db->loadAssocList(); > > return $list; > > > >From here: > > // updateAttributes() method code > $db =& JFactory::getDBO(); > > $last_pid = 0; > $first = 1; > $imp=array(); > if ($list){ > foreach ($list as $entry){ > if ($entry['product_sku'] && !in_array($entry['product_sku'], > $imp)){ > $imp[] = $entry['product_sku']; > } > if (!$first){ > if ($last_pid != $entry['product_id']){ > $upsql = "update #__vm_product set > custom_attribute='".implode(';',$imp). > "' where product_id=".$last_pid; > $db->setQuery($upsql); > $db->query(); > $imp=array(); > $last_pid = $entry['product_id']; > } > }else{ > $first = 0; > } > } > } > This is the actual part that I find tedious and it is very generic, independent from if you use databases or just have arrays. These are all great suggestions, no complaints, I'm just wondering if someone has an elegant solution for this part. Jochen --~--~---------~--~----~------------~-------~--~----~ NZ PHP Users Group: http://groups.google.com/group/nzphpug To post, send email to [email protected] To unsubscribe, send email to [email protected] -~----------~----~----~----~------~----~------~--~---
