CodeIgniter Forums
Can't access database table - 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: Can't access database table (/showthread.php?tid=40242)



Can't access database table - El Forum - 04-03-2011

[eluser]mwaidmann[/eluser]
hi there,

i'm pretty new to codeigniter and i'm playing around with some ideas. now i'm getting a problem while catching data from a database.

my controller function calls different functions in my model to get data from different tables. but only one table answers correct. the second table never returns anything. if i use a different controller and model to access data from this table it works fine.

thanks for any help or suggestions!
maik


Can't access database table - El Forum - 04-03-2011

[eluser]InsiteFX[/eluser]
If you want help you have to show your code!

InsiteFX


Can't access database table - El Forum - 04-03-2011

[eluser]mwaidmann[/eluser]
Model:
Code:
class leuchttisch_model extends CI_Model {
    

    function list_leuchttische()
    {
        
        $query = $this->db->get('TABLE1');
        
        if($query->num_rows == 1){
            $temp = $query->result();
            return $temp;
        }
    }
    
    function list_clients()
    {
        
        $query = $this->db->get('TABLE2');
                
        if($query->num_rows == 1){
            $temp = $query->result();
            return $temp;
        }
    }
        
}

Controller:
Code:
<?php

class Leuchttisch extends CI_Controller{
    
    function __construct()
    {
        parent::__construct();
        $this->is_logged_in();
    }
    
    function uebersicht()
    {
    
        $this->load->model('leuchttisch_model');
        
        // leuchttische
        $leuchttische = $this->leuchttisch_model->list_leuchttische();
        $clients =  $this->leuchttisch_model->list_clients();
        
        $data['clients'] = $clients;        
        $data['leuchttische'] = $leuchttische;
        
        $data['main_content'] = 'uebersicht';
        $this->load->view('includes/template',$data);
        
    }

    
    function is_logged_in()
    {
        
        $is_logged_in = $this->session->userdata('is_logged_in');
        
        if(!isset($is_logged_in) || $is_logged_in != TRUE)
        {
            echo 'Kein Zugang!';
            die();
        }
        
    }    
    

}

TABLE2 is the one i can't access.


Can't access database table - El Forum - 04-03-2011

[eluser]InsiteFX[/eluser]
Code:
if($query->num_rows == 1){
}
// should be
if($query->num_rows() > 0){
}

Controller:
Code:
// leuchttische
$leuchttische = $this->leuchttisch_model->list_leuchttische();
$clients =  $this->leuchttisch_model->list_clients();
        
$data['clients'] = $clients;        
$data['leuchttische'] = $leuchttische;

// Should be like this!

// leuchttische
$data['leuchttische'] = $this->leuchttisch_model->list_leuchttische();
$data['clients']      = $this->leuchttisch_model->list_clients();

There is no reason why you should not be able to retrive both tables! But both tables have to be in the same database!

Are both your tables named TABLE1 and TABLE2 ?

InsiteFX


Can't access database table - El Forum - 04-04-2011

[eluser]mwaidmann[/eluser]
Thx for your help Smile


Can't access database table - El Forum - 04-04-2011

[eluser]Unknown[/eluser]
Hi,
Good! So a SQL table linked into an Access database. I think that the issue will be on ... I can't see why they would eliminate that from the 2008 version.

_______
Daniel

Learn English Online


Can't access database table - El Forum - 04-04-2011

[eluser]InsiteFX[/eluser]
And what does that have to do with this post?

InsiteFX


Can't access database table - El Forum - 04-04-2011

[eluser]cideveloper[/eluser]
Spam for the link in signature