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

[eluser]ywftdg[/eluser]
There seems no obvious way to rewrite this query, I am just going to ditch this or hire someone. No matter how many ways I try to say 'while result' or 'foreach' it kills my controller or kills my models, seems CI doesn't want to do things this way. I am close to tossing y computer out the window, not worth the stress. I do not understand how something so basic as a loop can be so confusing.

Model
Code:
function get_bundles()    {
        $this->db->select('pSku, pName, pCost, pPrice, pSkulist');
        $this->db->where("pSkulist <> ''");
        $this->db->from('products');
        $query = $this->db->get();
        return $query->result();
        
    }

Controller
Code:
$query = $this->reports->get_bundles();
        
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $nothing = '';
            }
        }

Also, when I try to run the if statement in the model instead, it wont work, nor do I understand how to get it to"add" this results to my return$query last line.

Code:
function get_bundles()    {
        $this->db->select('pSku, pName, pCost, pPrice, pSkulist');
        $this->db->where("pSkulist <> ''");
        $this->db->from('products');
        $query = $this->db->get();
        
        foreach ($query->result() as $row) { // ok if above found item, run this also
            $thelist = $query->row('pSkulist');
            $this->db->select('sum(pPrice) as pricesum');
            $this->db->where_in('pSku', $thelist);
            $this->db->from('products');
            $queryb = $this->db->get(); // now thatI got the result, how can it be joined to the first queries result?
        }
        
        return $query->result();
        
    }

No matter what sort of scenario I try here, this wont work. Its just amazing how ridiculous this is, because it was so easy to write in my old code. Im looking at this wrong somehow, at this point i'm at a dead stop, I have tried endless methods, none of these work ad im just talking to myself on here now, hahaha.


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