Welcome Guest, Not a member yet? Register   Sign In
Undefined index
#1

[eluser]paulcj2[/eluser]
I'm setting up my third revision of /controlers/welcom.php and getting the error message:
Quote:Message: Undefined index: hm_pg_title
Filename: controllers/homepage.php
Line Number: 46

My first revision worked fine with this code:
Code:
//next we'll need to pull the home page info from database
    $this->load->database();
    $query = $this->db->query("SELECT hm_pg_title, hm_pg_descrip, hm_pg_text FROM website WHERE site_address = '$site_address'");
    
    foreach ($query->result() as $row)
        {
        $title = $row->hm_pg_title;
        $descrip = $row->hm_pg_descrip;
        $text = $row->hm_pg_text;
        }
Here is my third revision:
Code:
//------------------------------------------------------------------------
    // get page header info
    //------------------------------------------------------------------------
    $header_data['hm_pg_title'];
    $header_data['hm_pg_descrip'];
    $this->load->database();
        $sql = "
            SELECT
                hm_pg_title,
                hm_pg_descrip
            FROM
                website
            WHERE
                site_address = '$site_address'";
        $rs = $this->db->query($sql);
        foreach ($rs->result() as $row) {
            $header_data['hm_pg_title'] = $row->hm_pg_title;
            $header_data['hm_pg_descrip'] = $row->hm_pg_descrip;
        }
What am I missing?
#2

[eluser]paulcj2[/eluser]
I fixed it with:
Code:
$header_data['hm_pg_title'] = array();
    $header_data['hm_pg_descrip'] = array();
Now I'm getting:
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined variable: hm_pg_text
Filename: views/homepage.php
Line Number: 30
The controller code is:
Code:
//------------------------------------------------------------------------
        //get page content
        //------------------------------------------------------------------------
        $page_data["hm_pg_title"] = array();
        $page_data["hm_pg_text"] = array();
        $this->load->database();
        $sql = "
            SELECT
                hm_pg_title,
                hm_pg_text
            FROM
                website
            WHERE
                site_address = '$site_address'";
        $rs = $this->db->query($sql);
        foreach ($rs->result() as $row) {
            $page_data['hm_pg_title'] = $row->hm_pg_title;
            $page_data['hm_pg_text'] = $row->hm_pg_text;
            }
The views code is:
Code:
//to display home page values
        echo "<li>Page title: $hm_pg_title</li>\n";
        echo "<li>Site address: $site_address</li>\n";
        echo "<li>Text: $hm_pg_text</li>\n"; //line 30
Why would $hm_pg_title work, but not $hm_pg_text?
#3

[eluser]paulcj2[/eluser]
The plot thickens. Turns out the first array on the controller page is being ready by the views page, but the second one isn't.

The controller:
Code:
//------------------------------------------------------------------------
        // get page header info
        //------------------------------------------------------------------------
        $header_data['hm_pg_title'] = array();
        $header_data['hm_pg_descrip'] = array();
        $this->load->database();
                $sql = "
            SELECT
                hm_pg_title,
                hm_pg_descrip
            FROM
                website
            WHERE
                site_address = '$site_address'";
        $rs = $this->db->query($sql);
        foreach ($rs->result() as $row) {
            $header_data['hm_pg_title'] = $row->hm_pg_title;
            $header_data['hm_pg_descrip'] = $row->hm_pg_descrip;
            }
                
        //------------------------------------------------------------------------
        //get page content
        //------------------------------------------------------------------------
        $page_data['hm_pg_title'] = array();
        $page_data['hm_pg_text'] = array();
        $this->load->database();
        $sql = "
            SELECT
                hm_pg_title,
                hm_pg_text
            FROM
                website
            WHERE
                site_address = '$site_address'";
        $rs = $this->db->query($sql);
        foreach ($rs->result() as $row) {
            $page_data['hm_pg_title'] = $row->hm_pg_title;
            $page_data['hm_pg_text'] = $row->hm_pg_text;
            }
.....
        //------------------------------------------------------------------------
        // load views
        //------------------------------------------------------------------------
        $this->load->view('page/header', $header_data);    
        $this->load->view('homepage', $page_data);

The view:
Code:
//to display home page values
        echo "<li>Page title: $hm_pg_title</li>\n";
        echo "<li>Site address: $site_address</li>\n";
        echo "<li>Home page description: $hm_pg_descrip</li>\n";
        echo "<li>Home page text: $hm_pg_text</li>\n";
Again, what am I missing?
#4

[eluser]paulcj2[/eluser]
I go this to work. No need to respond.




Theme © iAndrew 2016 - Forum software by © MyBB