...

View Full Version : Put attributes of 3 products in a comparison table



lau87
04-24-2012, 02:38 PM
I am stuck with showing the attributes of 3 selected products from my webshop.
Users can select 2 or max 3 products and the slug of the products will be added to the comparison part, with the following code:

$sessionName = $aController[1];
$aCompare = &$_SESSION[$sessionName];
if (isset($aController[4]) && ($aController[4] == 'compare')) {
if (isset($aController[5]) && ($aController[5] == 'add')) {
$aCompare[$aController[6]] = 1;
}
}


I have a MySQL table 'vvs_webshop_specification' with a list of all specifications with its units.
I also have a MySQL table 'vvs_webshop_specification_connect_product' that connect the specification to the product together with a value for that particual specification.

With the code underneath I can show the specifications and its values of the selected products using the slug:
(EDIT code to multi array - see below)
The problem I have is that I get 3 times the specification list in front of the values. I only need 1 specification list, followed by 3 columns of values from the 3 selected products.
Another problem is that not every product has the same specification. Product A can have a specification 'weight' while Product B doesn't have this attribute. In that case, I want to add a '-' to the value list.

Can someone explain how I can solve the first problem: to show 1x the specification list on the left, followed by the values of the products.

EDIT:
I managed to change the output to multi array with:

foreach ($aCompare as $compareProduct => $productData) {
$sQueryF = "SELECT p.name, s.specification, s.unit, c.svalue
FROM vvs_webshop_product AS p
LEFT JOIN vvs_webshop_specification_connect_product AS c
ON k.product_id = p.id
LEFT JOIN vvs_webshop_specification AS s
ON s.id = c.specification_id
WHERE p.slug = '".mysql_real_escape_string($compareProduct)."'";
if (!$sResultF = mysql_query($sQueryF)) {
echo 'Error sql';
} else {
if (mysql_num_rows($sResultF) > 0) {
$aSpecsProduct[$compareProduct] = array();
while ($objF = mysql_fetch_assoc($sResultF)) {
$aSpecsProduct[$compareProduct]['name'] = $objF['name'];
$aSpecsProduct[$compareProduct][$objF['id']] = array('specification' => $objF['specification'],
'value' => $objF['svalue'],
'unit' => $objF['unit']);
}
}
}
}


OUTPUT with

echo '<pre>';
print_r($aSpecsProduct);
echo '</pre>';

is:

Array
(
[c-1103-5-pca-x-tra] => Array
(
[name] => C 110.3-5 PCA X-tra
[2] => Array
(
[specification] => Afmeting (L*B*H)
[value] => 240*240*660
[unit] => mm
)

[6] => Array
(
[specification] => Elektrische aansluitwaarde
[value] => 230
[unit] => Volt/50 Hz
)

[9] => Array
(
[specification] => Garantietermijn
[value] => 5
[unit] => jaar
)

[46] => Array
(
[specification] => Automatische start/stop
[value] => Ja
[unit] =>
)

)

[c-1103-5-pc-x-tra-nu-bij-de-hogedrukreinigerxpert] => Array
(
[name] => C 110.3-5 PC X-TRA Nu bij de hogedrukreinigerXpert
[2] => Array
(
[specification] => Afmeting (L*B*H)
[value] => 240x240x660
[unit] => mm
)

[5] => Array
(
[specification] => Elektrische aansluitwaarde
[value] => 1.4
[unit] => kw
)

[9] => Array
(
[specification] => Garantietermijn
[value] => 5
[unit] => jaar
)

[40] => Array
(
[specification] => Watertoevoertemperatuur
[value] => Maximaal 40
[unit] => C
)

)

)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum