Welcome Guest, Not a member yet? Register   Sign In
Selecting views
#1

[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?
#2

[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
#3

[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
#4

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

Randy
#5

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

MadZo




Theme © iAndrew 2016 - Forum software by © MyBB