Welcome Guest, Not a member yet? Register   Sign In
Reading from database table
#10

[eluser]TheFuzzy0ne[/eluser]
A blank page normally means that an error is bring thrown, but you don't have error reporting enabled. Try putting this at the top of your index.php file (and don't forget to remove it when you're site goes live):
Code:
ini_set('display_errors', '1');
error_reporting(E_ALL);

I would suggest you have a language model. Something like this (untested):
Code:
class Language_m extends CI_Model {
    
    protected $short_lang = 'en';
    
    function set_lang($short_lang = 'en')
    {
        $this->short_lang = $short_lang;
    }
    
    function get($word_key = '')
    {
        if ( ! $word_key)
        {
            return FALSE;
        }
        
        $res = $this->db
            ->select($word_key);
            ->where('lang_short', $this->short_lang);
            ->get_where('language')->row_array();
    
        if ( ! $res)
        {
            return FALSE;
        }
        
        return $res;
    }
}

So from your controller:
Code:
// Load the language model (should be loaded via ./application/config/autoload.php).
$this->load->model('language_m', 'db_lang');

// Set the short language code (You could do this in your MY_Controller constructor).
$this->db_lang->set_lang($this->session->userdata('short_lang'));

// Print a word.
echo = $this->db_lang->get('word');

// Or get multiple words in one database query.
$words = $this->db_lang->get(array(
    'word_1',
    'word_2',
    'word_3',
));

// Print them.
echo $words['word_1'] . '<br />';
echo $words['word_2'] . '<br />';
echo $words['word_3'] . '<br />';

This could be improved upon in several ways. For example, you could have a db_lang() helper function, or maybe add a method that will simply preloads the translations into the model, so you don't hit the database once for each word.

I also recommend you restructure your table so you don't have to add a new column for each word.


Messages In This Thread
Reading from database table - by El Forum - 04-08-2013, 09:25 AM
Reading from database table - by El Forum - 04-09-2013, 12:29 AM
Reading from database table - by El Forum - 04-09-2013, 01:04 AM
Reading from database table - by El Forum - 04-09-2013, 01:17 AM
Reading from database table - by El Forum - 04-09-2013, 01:27 AM
Reading from database table - by El Forum - 04-09-2013, 01:35 AM
Reading from database table - by El Forum - 04-09-2013, 03:41 AM
Reading from database table - by El Forum - 04-09-2013, 03:46 AM
Reading from database table - by El Forum - 04-20-2013, 07:36 AM
Reading from database table - by El Forum - 04-20-2013, 08:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB