Multiple Join - Intelligente Datenstruktur bei mehrsprachigkeit

Habs jetzt auf die "klassische" Variante mit zwei Schleifen gelöst. Deine Variante ist auch nicht schlecht, allerdings etwas verwirrend wenn ich mir den Code in zwei Jahren nochmals ansehen würde ;)

Hier die (relativ simple) Lösung, die mir einen mehrdimensionalen Array in der jeweiligen Sprache zurückliefert:

PHP:
function getManufacturersAvailable($startCount,$showResultCount,$searchQuery)
	{
		$manufacturers=array();
		
		// UTF8 Encoded auslesen
		//-------------------------------------------------------------------
		$sql = 'SET NAMES \'utf8\' ';
		$result =$this->_db->query($sql);
		
		$searchQuery=$this->_db->escapeSimple($searchQuery);
		
		$sql = ' SELECT '
			. ' tbl_manufacturer.`pk_manufacturer_id` AS `pk_manufacturer_id` '
			. ' FROM `tbl_manufacturer` AS `tbl_manufacturer` '
			. ' WHERE tbl_manufacturer.`manufacturer_deleted` IS NULL '
			. ' LIMIT '.$this->_db->escapeSimple($startCount).', '.$this->_db->escapeSimple($showResultCount).' ';
		$manufacturerResult =$this->_db->query($sql);	
		while($manufacturerRow = $manufacturerResult->fetchRow(DB_FETCHMODE_ASSOC)):
			$sql = ' SELECT '
				. ' tbl_manufacturer_description.`manufacturer_description_value` AS `manufacturer_description_value`, '
				. ' tbl_manufacturer_property.`manufacturer_property_key` AS `manufacturer_property_key` '
				. ' FROM `tbl_manufacturer_description` AS `tbl_manufacturer_description` '
				. ' INNER JOIN `tbl_manufacturer_property` AS `tbl_manufacturer_property` ON `tbl_manufacturer_description`.`fk_manufacturer_property_id`=`tbl_manufacturer_property`.`manufacturer_property_id` '
				. ' WHERE tbl_manufacturer_description.`fk_manufacturer_id`=\''.$manufacturerRow['pk_manufacturer_id'].'\' '
				. ' AND tbl_manufacturer_description.`fk_language_id`=\''.$_SESSION['sess_language_id'].'\' ';
			$manufacturerPropertyResult =$this->_db->query($sql);
			while($manufacturerPropertyRow = $manufacturerPropertyResult->fetchRow(DB_FETCHMODE_ASSOC)):		
				$manufacturers[$manufacturerRow['pk_manufacturer_id']][$manufacturerPropertyRow['manufacturer_property_key']]=$manufacturerPropertyRow['manufacturer_description_value'];
				echo $manufacturers[$manufacturerRow['pk_manufacturer_id']][$manufacturerPropertyRow['manufacturer_property_key']].'<br>';
			endwhile;
		endwhile;	

		return $manufacturers;
	}

Habe noch ein Attribut "KEY" bei den Properties eingeführt. Das ist beispielsweise "URL", "DESCRIPTION" und "NAME". Damit wird es etwas leserlicher als die indizierung direkt über den Primary Key..
 

Neue Beiträge

Zurück