Categories > TinyButStrong general >

multiplying 2 results from aggregate

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: ryakich
Date: 2006-12-22
Time: 04:35

multiplying 2 results from aggregate

I am using aggregate on two columns, and want to multiply there end result for a grand total.

Template Code
    <div>
        <h3>Provider: [m.login;block=div]</h3>
        <table summary="Current Inventrory" cellpadding="0" cellspacing="0">
            <tr>
                <th>Product / <span>SKU</span></th>
                <th class="number">List Price</th>
                <th class="number">Qty</th>
                <th class="number">Cubes</th>
                <th class="number">Subtotal Cubes</th>
            </tr>
            <tr>
                <td>[p.product; block=tr; aggregate= avail:sum, value:sum; p1=[m.login]]
                    <br /><span>[p.productcode;p1=[main.login]]</span></td>
                <td class="number">[p.list_price;p1=[main.login];frm='0000.00']</td>
                <td class="number">[p.avail;p1=[main.login]]</td>
                <td class="number">[p.value;p1=[main.login]]</td>
                <td class="number">[p.avail;p1=[main.login];ope=mul:[p.value;p1=[m.login]]]</td>
            </tr>
            <tr class="totals">
                <td>Totals</td>
                <td>&nbsp;</td>
                <td class="number">[p.avail:sum]</td>
                <td class="number">[p.value:sum]</td>
                <td class="number">[p.avail:sum;*=[p.value:sum]]</td>
            </tr>
        </table>
    </div>

PHP Code
include_once('_inc/'.'tbs_class.php') ;
include_once('_inc/'.'tbs_plugin_aggregate.php');
include_once('_inc/'.'tbs_plugin_plus.php') ;
include_once('_inc/'.'dbcnx.php');

$main="SELECT
    login
    FROM xcart_customers
    WHERE usertype='P'
    ORDER BY login";

$sub="SELECT
    xcart_products.productcode,
    xcart_products.product,
    xcart_products.provider,
    xcart_products.list_price,
    xcart_products.avail,
    xcart_extra_field_values.value
    FROM xcart_products
    JOIN xcart_extra_field_values
    ON xcart_products.productid = xcart_extra_field_values.productid
    WHERE xcart_products.provider = '%p1%'
    ORDER BY xcart_products.productcode";

$curPage="inventory";

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate('_tpl/'.$curPage.'.html');
$TBS->MergeBlock('m',$cnx_id,$main);
$TBS->MergeBlock('p',$cnx_id,$sub);
mysql_close($cnx_id);
$TBS->Show();


Any suggestions on how to get this to work correctly ? i cant understand why it can see the values of [p.avail:sum;*=[p.value:sum]] but when I try anything to multiply them together i get a big fat 0.

Thanks for any help.
By: sheepy
Date: 2006-12-22
Time: 09:10

Re: multiplying 2 results from aggregate

The problem is since TBS is merged top to bottom, when it tries to merge [p.avail:sun; *= ... ] or [p.avail:sun; ope=mul: ... ], the multiplier (also a p) is not yet merged.  Since the string "[p.value]" or "[p.value:sum] is evaluated to zero, the value will be multiplied by zero and, as a result, it comes out zero.