Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Jul 2009
    Posts
    20
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy Put attributes of 3 products in a comparison table

    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:
    PHP 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:
    PHP Code:
    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
    PHP Code:
    echo '<pre>';
    print_r($aSpecsProduct);
    echo 
    '</pre>'
    is:
    Code:
    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
                    )
    
            )
    
    )
    Last edited by lau87; 04-24-2012 at 04:42 PM. Reason: Change to multi array


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •