Welcome Guest, Not a member yet? Register   Sign In
Solved : Newbie question - Working with models
#10

[eluser]ywftdg[/eluser]
Maybe it will all make more sense if I posted the old php code. This code is a little wild, but it should help show how I am trying to say ok do this first thing. Now I got these values, go on to the next query. I just don't get how in CI, you go from one query to the next. Where below makes total sense to me, because I can call my rows from previous queries, etc.

Code:
$query = "select dpercentages from designer where ddesignerid = $DesignerId";
$result = mysql_query($query);
if($row = mysql_fetch_row($result)) {
    $BasePercentage = $row[0];
} else {
    $BasePercentage = 0;
}

$query = "select psku, pname, pcost, pprice, pskulist from products where pskulist <> ''";
$result = mysql_query($query);
$GrandTotal = 0;
$GrandQty = 0;
$GrandSales = 0;

// !!!!!!!!!!!!!!!!!!!!



while($row = mysql_fetch_row($result)) {

    $BundleTotal = 0;
    $BundleProfit = 0;


    // Get the non-discounted total for this bundle
    $query2 = "select sum(pprice) from products where psku in ($row[4])";
    $result2 = mysql_query($query2);
    
    if($row2 = mysql_fetch_row($result2)) {
        $BaseBundlePrice = $row2[0];
    } else {
        $BaseBundlePrice = 0;
    }
    
    $Discount = $row[3] / $BaseBundlePrice;



    $query2 = "select psku, pname, pcost, pprice from products where psku in ($row[4]) and pdesignerid = $DesignerId";
    $result2 = mysql_query($query2);
    if(mysql_num_rows($result2) > 0) {
    while($row2 = mysql_fetch_row($result2)) {

        $query3 = "select sum(oquantity) from orderdetail inner join receipt on oOrderNum = rOrderNum where osku = '$row[0]' and " . $query_date;
        $result3 = mysql_query($query3);
        if($row3 = mysql_fetch_row($result3)) {
            $BundleProfit += ($row2[3] * $Discount) * ($BasePercentage / 100);
            $BundleTotal += ((($row2[3] * $Discount) * $row3[0]) * ($BasePercentage / 100));
            }

    }

            $GrandQty += $row3[0];
    $GrandTotal += $BundleTotal;
    $GrandSales += $row[3] * $row3[0];


Messages In This Thread
Solved : Newbie question - Working with models - by El Forum - 08-11-2008, 12:26 AM
Solved : Newbie question - Working with models - by El Forum - 08-11-2008, 12:45 AM
Solved : Newbie question - Working with models - by El Forum - 08-11-2008, 01:00 AM
Solved : Newbie question - Working with models - by El Forum - 08-11-2008, 01:12 AM
Solved : Newbie question - Working with models - by El Forum - 08-11-2008, 01:20 AM
Solved : Newbie question - Working with models - by El Forum - 08-11-2008, 01:33 AM
Solved : Newbie question - Working with models - by El Forum - 08-11-2008, 01:43 AM
Solved : Newbie question - Working with models - by El Forum - 08-11-2008, 02:08 AM
Solved : Newbie question - Working with models - by El Forum - 08-11-2008, 02:15 AM
Solved : Newbie question - Working with models - by El Forum - 08-11-2008, 03:39 AM
Solved : Newbie question - Working with models - by El Forum - 08-12-2008, 12:15 AM
Solved : Newbie question - Working with models - by El Forum - 08-12-2008, 01:45 AM
Solved : Newbie question - Working with models - by El Forum - 08-12-2008, 11:44 PM
Solved : Newbie question - Working with models - by El Forum - 08-13-2008, 07:21 AM



Theme © iAndrew 2016 - Forum software by © MyBB