CodeIgniter Forums

Full Version: [Solved] Not getting column from database correct?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have created a set_language library where I can get the language code from my setting table and at the moment it is set as en.

So when I do this <?php echo $this->set_language->get_lang() ;?> it echos out en which is correct.

How ever when I try to get the directory value from my language table where code is en it does not return value. It should return directory name english.

What have I done wrong on my lang() function I have attached two images of database.


PHP Code:
<?php

class Set_language {

    public function __construct() {
        $this->ci =& get_instance();
        $this->ci->config->set_item('language'$this->lang());
    }

    public function lang() {
        $this->ci->db->select('*');
        $this->ci->db->from($this->ci->db->dbprefix 'language');
        $this->ci->db->where('code'$this->get_lang());
        $query $this->ci->db->get();

        $row $query->row();
        return $row->directory;
    }

    public function get_lang() {
        $this->ci->db->select('*');
        $this->ci->db->from($this->ci->db->dbprefix 'setting');
        $this->ci->db->where('item_name''admin_language');
        $query $this->ci->db->get();

        $row $query->row();
        return $row->item_value;
    }


Quote:Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM `language`, `setting` WHERE `item_name` = 'admin_language'' at line 1
SELECT *, * FROM `language`, `setting` WHERE `item_name` = 'admin_language'
Filename: C:/wamp/www/project/admin/application/libraries/Set_language.php
Line Number: 24


Any suggestions thanks in advance.
It did not work with the db select for some reason so just went with db get and where

PHP Code:
<?php

class Set_language {

    public function 
__construct() {
        
$this->ci =& get_instance();
        
//$this->ci->config->set_item('language', $this->lang());
    
}

    public function 
lang() {
        
$this->ci->db->where('code'$this->get_lang());
        
$query $this->ci->db->get($this->ci->db->dbprefix 'language');

        
$row $query->row();
        return 
$row->directory;
    }

    public function 
get_lang() {
        
$this->ci->db->where('item_name''admin_language');
        
$query $this->ci->db->get($this->ci->db->dbprefix 'setting');

        
$row $query->row();
        return 
$row->item_value;
    }