CodeIgniter Forums
retrieving and showing data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: retrieving and showing data (/thread-65690.html)

Pages: 1 2


retrieving and showing data - davy_yg - 07-12-2016

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?


RE: retrieving and showing data - arma7x - 07-12-2016

The message 'Array to string conversion' mean you echoing array datatype without looping it to retrieve each subvalue.


RE: retrieving and showing data - davy_yg - 07-12-2016

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?

\


RE: retrieving and showing data - arma7x - 07-12-2016

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


RE: retrieving and showing data - mwhitney - 07-12-2016

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).


RE: retrieving and showing data - rtenny - 07-12-2016

(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.


RE: retrieving and showing data - InsiteFX - 07-12-2016

He's open <TR> tags but he is never closing any of them.


RE: retrieving and showing data - davy_yg - 07-12-2016

(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();        
        
    




RE: retrieving and showing data - InsiteFX - 07-13-2016

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.


RE: retrieving and showing data - rtenny - 07-13-2016

(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;