CodeIgniter Forums
Selecting views - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Selecting views (/showthread.php?tid=12821)



Selecting views - El Forum - 11-01-2008

[eluser]no_Ob[/eluser]
Hi there

I have got a very annoying problem which is looks like quite simple,but I can't figure it out.

I would like to choose the loaded view according to the database results.

Controller:
Code:
class Categories extends Controller {


    function index()
        {
         parent::Controller();
        
         $this->load->view('index');
         $this->load->view('partial/home_view');    
          $this->load->view('index2');    
            
        }

    function choice($platform,$what)
    {
        parent::Controller();
        
        $data['platform'] = $platform;
        $data['what'] = $what;
        
        
        $this->load->model('shopmodel');
        $result['query'] = $this->shopmodel->selectkonzol($data);
        
    
        $data[$platform] = 'T';
        $this->load->view('index',$data);
        
        
        if(!empty($result))
        {
        $this->load->view('products/games',$result);    
        }
        else
        {
        $this->load->view('products/noproduct',$database);
        }

        $this->load->view('index2');
    }
}

Model
Code:
class Shopmodel extends Model {

    function index()
    {
        // Call the Model constructor
        parent::Model();
            
    }

    function selectkonzol($data)
    {
        
    $platform   = $data['platform'];
    $what   = $data['what'];
    
    if($what=="games")
    {
    $query = "SELECT * FROM `games` WHERE `platform`='$platform'";
    }
    else
    {
        $query = "SELECT * FROM `products` WHERE `platform`='$platform' and 'productcat'='$what'";
    }
    
    
    $result=$this->db->query($query);
    return $result->result();
    }
}

If I have no results, it doesnt load the other viewSad

Why is this happening?


Selecting views - El Forum - 11-01-2008

[eluser]Randy Casburn[/eluser]
Are you sure it doesn't load the view, or does it load the view and not show any data? Where have you declared or assigned any values to $database in the method choice()?

Randy


Selecting views - El Forum - 11-01-2008

[eluser]no_Ob[/eluser]
You are right it.
It loads everytime the product/game view.

Sorry this $database variable has to be renamed to $data


Selecting views - El Forum - 11-01-2008

[eluser]Randy Casburn[/eluser]
Great! Glad it was easy and glad I could help,

Randy


Selecting views - El Forum - 11-02-2008

[eluser]no_Ob[/eluser]
Thank you very much

MadZo