Welcome Guest, Not a member yet? Register   Sign In
problems with echo arrays
#1

[eluser]chejnik[/eluser]
Hello, I would like to built dynamically a table (based on database values from Database settings table) with form elements and fill these elements from sql query made on Dictionary database with dictionary values)

my model function
Code:
function findExactWord($id)
    {
       $this->db->where('id', $id);
    $query = $this->db->get('is-cs');
      return $query->result_array();
    }

my controller
Code:
function editWord($id)
    {
        $this->load->model('Dictionary_model');
            
        //returns array
        $word = $this->Dictionary_model->findExactWord($id);    
        $data = $this->makePageHeadwordFill($word);
        
        $this->load->view('editheadwordview', $data);
    }

    function makePageHeadwordFill($word)
    {
        $this->load->model('Settings_model');
                
        // returns array
        $page = $this->Settings_model->select_makePage($this->session->userdata('i'));
        
        
        $i=0; $j=0;
        foreach ($page as $item) {
            $i++; $j++;
            $headings[$i]= $item["onWeb"];
            switch ($item["nameInputElement"]) {
            // hidden element
            case '0':
                $elements[$i]=$item["onWeb"];
                $i++;
                $elements[$i]= form_hidden($item["databaseRowName"], $word[$j];
                
                break;
            // input element
            case '1':
                $elements[$i]=$item["onWeb"];
                $i++;
                $elements[$i]= form_input($item["databaseRowName"], $word[$j];    
            
                break;
            // text element
            case '2':
                $elements[$i]=$item["onWeb"];
                $i++;
                $elements[$i]= form_textarea($item["databaseRowName"], $word[$j]);
                break;
            default:
            }

            }

            $output ='';
            $table = $this->table->make_columns($elements, 2);
            $data["completePage"] = $this->table->generate($table);
            return $data;
    }

my view
Code:
echo $completePage;

Actually I am having troubles with using the array $word. I do not know how to output the values.
Thank you.
With regards Ales
#2

[eluser]wiredesignz[/eluser]
I see a few errors in the code you have posted. But for what you have asked, $word is an array of arrays return from the query.

So $word[$j] is actually returning an array(), Which represents a row of data not a string.

You need an additional key value to determine which element of data you wish to work with.

$word[$j][?]
#3

[eluser]chejnik[/eluser]
Hello, thank you for help. Now I know how to get to the value

Code:
function makePageHeadwordFill($word)
    {
        $this->load->model('Settings_model');
                
        // returns array
        $page = $this->Settings_model->select_makePage($this->session->userdata('i'));
        
        
        $i=0; $j=0;
        foreach ($page as $item) {
            $i++; $j++;
            $headings[$i]= $item["onWeb"];
            switch ($item["nameInputElement"]) {
            // hidden element
            case '0':
                $elements[$i]=$item["onWeb"];
                $i++;
                $elements[$i]= form_hidden($item["databaseRowName"], $word[0][trim($item["databaseRowName"])]);
                
                break;
            // input element
            case '1':
                $elements[$i]=$item["onWeb"];
                $i++;
                $elements[$i]= form_input($item["databaseRowName"], $word[0][trim($item["databaseRowName"])]);    
            
                break;
            // text element
            case '2':
                $elements[$i]=$item["onWeb"];
                $i++;
                $elements[$i]= form_textarea($item["databaseRowName"], $word[0][trim($item["databaseRowName"])]);
                break;
            default:
            }

            }

            $output ='';
            $table = $this->table->make_columns($elements, 2);
            $data["completePage"] = $this->table->generate($table);
            return $data;
    }

Because it is a single row I come to the array first array [0]
Have you seen some other mistakes, and do you think it is generally good idea to get the name of the database tables and make from them dynamically the html tables filled with database values?
I implement this principle because I want to be the database tables fully modifiable by new users according to each language specific needs in dictionary development.
Thanks Ales




Theme © iAndrew 2016 - Forum software by © MyBB