Welcome Guest, Not a member yet? Register   Sign In
retrieving and showing data
#1

Hello,

I am trying to show data in here but have not been successful yet.


controllers/cpages.php

PHP Code:
public function pcategories() { 
    
        
$this->Mpages->retrieve_parentctg();

        
$data['ctgparent_name'] = $this->Mpages->retrieve_parentctg();
        
$data['ctgparent_description'] = $this->Mpages->retrieve_parentctg();
        
        
$this->load->view('pcategories'$data); 
        
    } 



views/pcategories.php


PHP Code:
<div class="widget-box">
                        <
div class="widget-title"><h5>Parent Categories</h5></div>
                        <
div class="widget-content">
                        
                        <
table border="0" style="width: 100%; height: 90px;">
                            <
tr>
                                <
td>PARENT NAME</td>
                                <
td>DESCRIPTION</td>
                                <
td>EDIT</td>
                                <
td>DELETE</td>    
                            </
td>
                            <
tr>
                                <
td>Mens</td>
                                <
td><?php echo $ctgparent_name?></td>
                                <td><button type="button" class="edit" onclick="location.href='<?php echo site_url('cpages/editparentctg'); ?>';">EDIT</button></td>
                                <td><button type="button" class="delete" href="adminform.php">DELETE</button></td>    
                            </td>    
                            <tr>
                                <td>Womens</td>
                                <td><?php echo $ctgparent_description?></td>
                                <td><button type="button" class="edit" onclick="location.href='<?php echo site_url('cpages/addparentctg'); ?>';">EDIT</button></td>
                                <td><button type="button" class="delete" href="adminform.php">DELETE</button></td>    
                            </td>    
                        </table>            
                        </div>
                    </div> 

The Result:

A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: views/pcategories.php
Line Number: 54
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\pcategories.php
Line: 54
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php
Line: 46
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php
Line: 315
Function: require_once
Array

Womens
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: views/pcategories.php
Line Number: 60
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\pcategories.php
Line: 60
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php
Line: 46
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php
Line: 315
Function: require_once


SQL DATABASE - TABLE: menu_parent


ctgparent_name                    ctgp_no                  ctgparent_description
[Image: dot.gif]
Men                                        0                             Description


How to fix the error so that I can see the result?
" If I looks more intelligence please increase my reputation."
Reply
#2

(This post was last modified: 07-12-2016, 07:44 AM by arma7x.)

The message 'Array to string conversion' mean you echoing array datatype without looping it to retrieve each subvalue.
Keep calm.
Reply
#3

I try this:


views/pcategories.php


PHP Code:
<table border="0" style="width: 100%; height: 90px;">
                            <
tr>
                                <
td>PARENT NAME</td>
                                <
td>DESCRIPTION</td>
                                <
td>EDIT</td>
                                <
td>DELETE</td>    
                            </
td>
                            
                            <?
php foreach($posts as $post){?>
                            <tr>
                                <td><?php echo $data['ctgparent_name']; ?></td>
                                <td><?php echo $data['ctgparent_description']; ?></td>
                                <td><button type="button" class="edit" onclick="location.href='<?php echo site_url('cpages/editparentctg'); ?>';">EDIT</button></td>
                                <td><button type="button" class="delete" href="adminform.php">DELETE</button></td>    
                            </td>    
                            <tr>
                                <td><?php echo $data['ctgparent_name']; ?></td>
                                <td><?php echo $data['ctgparent_description']; ?></td>
                                <td><button type="button" class="edit" onclick="location.href='<?php echo site_url('cpages/addparentctg'); ?>';">EDIT</button></td>
                                <td><button type="button" class="delete" href="adminform.php">DELETE</button></td>    
                            </td>
                            <?php }?> 
                            
                        </table> 



Controllers/cpages.php


PHP Code:
public function pcategories() { 
    
        
$this->Mpages->retrieve_parentctg();

        
$data['ctgparent_name'] = $this->Mpages->retrieve_parentctg();
        
$data['ctgparent_description'] = $this->Mpages->retrieve_parentctg();
        
        
$this->load->view('pcategories'$data); 
        
    } 


Still get this error message:

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: views/pcategories.php
Line Number: 54
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\pcategories.php
Line: 54
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php
Line: 46
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php
Line: 315
Function: require_once

Womens
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: views/pcategories.php
Line Number: 60
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\pcategories.php
Line: 60
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php
Line: 46
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php
Line: 315
Function: require_once

How to fix the error messages?

\
" If I looks more intelligence please increase my reputation."
Reply
#4

Didn't see any $data['posts'] in your controller. When passing $data to view(), the view file will have $posts as variable.
Keep calm.
Reply
#5

Your controller defines $data['ctgparent_name'] and $data['ctgparent_description'], then passes $data to the view. So, in the view, you would access this data as $ctgparent_name and $ctgparent_description.

As arma7x mentioned, you didn't show any code which defines $posts in the view or $data['posts'] in the controller, though I'd have to assume that it's defined somewhere, since you're not getting an error on the foreach() loop (unless you're calling $data somewhere before the view code you've included here).
Reply
#6

(07-12-2016, 07:34 AM)davy_yg Wrote: Hello,

I am trying to show data in here but have not been successful yet.


controllers/cpages.php

PHP Code:
public function pcategories() { 
    
        
$this->Mpages->retrieve_parentctg();

        
$data['ctgparent_name'] = $this->Mpages->retrieve_parentctg();
        
$data['ctgparent_description'] = $this->Mpages->retrieve_parentctg();
        
        
$this->load->view('pcategories'$data); 
        
    } 



views/pcategories.php


PHP Code:
<div class="widget-box">
                        <
div class="widget-title"><h5>Parent Categories</h5></div>
                        <
div class="widget-content">
                        
                        <
table border="0" style="width: 100%; height: 90px;">
                            <
tr>
                                <
td>PARENT NAME</td>
                                <
td>DESCRIPTION</td>
                                <
td>EDIT</td>
                                <
td>DELETE</td>    
                            </
td>
                            <
tr>
                                <
td>Mens</td>
                                <
td><?php echo $ctgparent_name?></td>
                                <td><button type="button" class="edit" onclick="location.href='<?php echo site_url('cpages/editparentctg'); ?>';">EDIT</button></td>
                                <td><button type="button" class="delete" href="adminform.php">DELETE</button></td>    
                            </td>    
                            <tr>
                                <td>Womens</td>
                                <td><?php echo $ctgparent_description?></td>
                                <td><button type="button" class="edit" onclick="location.href='<?php echo site_url('cpages/addparentctg'); ?>';">EDIT</button></td>
                                <td><button type="button" class="delete" href="adminform.php">DELETE</button></td>    
                            </td>    
                        </table>            
                        </div>
                    </div> 

The Result:

A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: views/pcategories.php
Line Number: 54
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\pcategories.php
Line: 54
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php
Line: 46
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php
Line: 315
Function: require_once
Array

Womens
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: views/pcategories.php
Line Number: 60
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\pcategories.php
Line: 60
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php
Line: 46
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php
Line: 315
Function: require_once


SQL DATABASE - TABLE: menu_parent


ctgparent_name                    ctgp_no                  ctgparent_description
[Image: dot.gif]
Men                                        0                             Description


How to fix the error so that I can see the result?

I think your function $this->Mpages->retrieve_parentctg(); is return an array rather then a plain string.
On the package it said needs Windows 7 or better. So I installed Linux.
Reply
#7

He's open <TR> tags but he is never closing any of them.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#8

(07-12-2016, 09:18 AM)rtenny Wrote:
(07-12-2016, 07:34 AM)davy_yg Wrote: Hello,

I am trying to show data in here but have not been successful yet.


controllers/cpages.php

PHP Code:
public function pcategories() { 
    
        
$this->Mpages->retrieve_parentctg();

        
$data['ctgparent_name'] = $this->Mpages->retrieve_parentctg();
        
$data['ctgparent_description'] = $this->Mpages->retrieve_parentctg();
        
        
$this->load->view('pcategories'$data); 
        
    } 



views/pcategories.php


PHP Code:
<div class="widget-box">
                        <
div class="widget-title"><h5>Parent Categories</h5></div>
                        <
div class="widget-content">
                        
                        <
table border="0" style="width: 100%; height: 90px;">
                            <
tr>
                                <
td>PARENT NAME</td>
                                <
td>DESCRIPTION</td>
                                <
td>EDIT</td>
                                <
td>DELETE</td>    
                            </
td>
                            <
tr>
                                <
td>Mens</td>
                                <
td><?php echo $ctgparent_name?></td>
                                <td><button type="button" class="edit" onclick="location.href='<?php echo site_url('cpages/editparentctg'); ?>';">EDIT</button></td>
                                <td><button type="button" class="delete" href="adminform.php">DELETE</button></td>    
                            </td>    
                            <tr>
                                <td>Womens</td>
                                <td><?php echo $ctgparent_description?></td>
                                <td><button type="button" class="edit" onclick="location.href='<?php echo site_url('cpages/addparentctg'); ?>';">EDIT</button></td>
                                <td><button type="button" class="delete" href="adminform.php">DELETE</button></td>    
                            </td>    
                        </table>            
                        </div>
                    </div> 

The Result:

A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: views/pcategories.php
Line Number: 54
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\pcategories.php
Line: 54
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php
Line: 46
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php
Line: 315
Function: require_once
Array

Womens
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: views/pcategories.php
Line Number: 60
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\pcategories.php
Line: 60
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php
Line: 46
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php
Line: 315
Function: require_once


SQL DATABASE - TABLE: menu_parent


ctgparent_name                    ctgp_no                  ctgparent_description
[Image: dot.gif]
Men                                        0                             Description


How to fix the error so that I can see the result?

I think your function $this->Mpages->retrieve_parentctg(); is return an array rather then a plain string.


How to make it works?


models/Mpages.php

PHP Code:
public function retrieve_parentctg()
    {
        
        $query 
$this->db->get('menu_parent');
        return $query->result();        
        
    

" If I looks more intelligence please increase my reputation."
Reply
#9

What is Mpages returning a result(),result_array(),row() or row_array()

If it doe's not end with an array then you are returning an object not an array.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#10

(07-12-2016, 09:30 PM)davy_yg Wrote:
(07-12-2016, 09:18 AM)rtenny Wrote:
(07-12-2016, 07:34 AM)davy_yg Wrote: Hello,

I am trying to show data in here but have not been successful yet.


controllers/cpages.php

PHP Code:
public function pcategories() { 
    
        
$this->Mpages->retrieve_parentctg();

        
$data['ctgparent_name'] = $this->Mpages->retrieve_parentctg();
        
$data['ctgparent_description'] = $this->Mpages->retrieve_parentctg();
        
        
$this->load->view('pcategories'$data); 
        
    } 



views/pcategories.php


PHP Code:
<div class="widget-box">
                        <
div class="widget-title"><h5>Parent Categories</h5></div>
                        <
div class="widget-content">
                        
                        <
table border="0" style="width: 100%; height: 90px;">
                            <
tr>
                                <
td>PARENT NAME</td>
                                <
td>DESCRIPTION</td>
                                <
td>EDIT</td>
                                <
td>DELETE</td>    
                            </
td>
                            <
tr>
                                <
td>Mens</td>
                                <
td><?php echo $ctgparent_name?></td>
                                <td><button type="button" class="edit" onclick="location.href='<?php echo site_url('cpages/editparentctg'); ?>';">EDIT</button></td>
                                <td><button type="button" class="delete" href="adminform.php">DELETE</button></td>    
                            </td>    
                            <tr>
                                <td>Womens</td>
                                <td><?php echo $ctgparent_description?></td>
                                <td><button type="button" class="edit" onclick="location.href='<?php echo site_url('cpages/addparentctg'); ?>';">EDIT</button></td>
                                <td><button type="button" class="delete" href="adminform.php">DELETE</button></td>    
                            </td>    
                        </table>            
                        </div>
                    </div> 

The Result:

A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: views/pcategories.php
Line Number: 54
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\pcategories.php
Line: 54
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php
Line: 46
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php
Line: 315
Function: require_once
Array

Womens
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: views/pcategories.php
Line Number: 60
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\views\pcategories.php
Line: 60
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\application\controllers\Cpages.php
Line: 46
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyGiondaCI\index.php
Line: 315
Function: require_once


SQL DATABASE - TABLE: menu_parent


ctgparent_name                    ctgp_no                  ctgparent_description
[Image: dot.gif]
Men                                        0                             Description


How to fix the error so that I can see the result?

I think your function $this->Mpages->retrieve_parentctg(); is return an array rather then a plain string.


How to make it works?


models/Mpages.php

PHP Code:
public function retrieve_parentctg()
    {
        
        $query 
$this->db->get('menu_parent');
        return $query->result();        
        
    


to find out what is actually returned add this just before the call of the view

print_r($data['ctgparent_name']);
die;
On the package it said needs Windows 7 or better. So I installed Linux.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB