Welcome Guest, Not a member yet? Register   Sign In
Verification error
#1

[eluser]Thiago Leao[/eluser]
please, i need help in the verification...

list_subcategory - controller
Code:
<?php
class List_sub_categoria extends Controller{
    
    function __construct(){
        parent::Controller();
    }
    function listar($maximo, $inicio){
        $this->db->orderby("subcategoria", "asc");
        $query = $this->db->get('subcategoria', $maximo, $inicio);
        $query->result();
    }
function index(){
        $param['subcategoria'] = $this->listar($maximo, $inicio);    
        $this->load->view('administracao/list_sub_categoria', $param);
                    
    }

list_subcategory - Views

Code:
<?php

LINE130 if($subcategoria[0]->id_sub == '') {
echo "<li>no categories registered!</li>";
}else{
foreach($subcategoria as $sub):
...content...
endforeach;
}
?&gt;

error

Code:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: administracao/list_sub_categoria.php
Line Number: 130

someone help?
thanks
#2

[eluser]joedy[/eluser]
It means there is no object you want to get.

$query->result() is used to returns as an array of "objects".

so it shouldn't be like this $subcategoria[0]->id_sub,

its $subcategoria->id_sub

I suggest You to show the data return 1st before doing next process. You can use print_r($subcsategoria);
#3

[eluser]theprodigy[/eluser]
Also, in your controller, you might want to return the result. You are calling the results function, but not setting anything to it, and not returning it.

Change:
Code:
function listar($maximo, $inicio){
        $this->db->orderby("subcategoria", "asc");
        $query = $this->db->get('subcategoria', $maximo, $inicio);
        $query->result();
    }

To:
Code:
function listar($maximo, $inicio){
        $this->db->orderby("subcategoria", "asc");
        $query = $this->db->get('subcategoria', $maximo, $inicio);
        return $query->result(); //    <---- RETURN the query result
    }
#4

[eluser]Thiago Leao[/eluser]
[quote author="theprodigy" date="1286269012"]Also, in your controller, you might want to return the result. You are calling the results function, but not setting anything to it, and not returning it.

Change:
Code:
function listar($maximo, $inicio){
        $this->db->orderby("subcategoria", "asc");
        $query = $this->db->get('subcategoria', $maximo, $inicio);
        $query->result();
    }

To:
Code:
function listar($maximo, $inicio){
        $this->db->orderby("subcategoria", "asc");
        $query = $this->db->get('subcategoria', $maximo, $inicio);
        return $query->result(); //    <---- RETURN the query result
    }
[/quote]

Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 0
Filename: administracao/list_sub_categoria.php
Line Number: 129


A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: administracao/list_sub_categoria.php
Line Number: 129

same error!
#5

[eluser]Thiago Leao[/eluser]
[quote author="joedy" date="1286265933"]It means there is no object you want to get.

$query->result() is used to returns as an array of "objects".

so it shouldn't be like this $subcategoria[0]->id_sub,

its $subcategoria->id_sub

I suggest You to show the data return 1st before doing next process. You can use print_r($subcsategoria);[/quote]

Code:
Array ( [0] => stdClass Object ( [id_sub] => 16 [id_category] => 24 [id_user] => 1 [subcategoria] => testee ) ) 1

Looks print_r($subcategoria);

i wait help!
thanks friends!
#6

[eluser]Thiago Leao[/eluser]
anyone? pls!
#7

[eluser]theprodigy[/eluser]
change your view to:
Code:
&lt;?php

if(! count($subcategoria)){
   echo "<li>no categories registered!</li>";
}else{
   foreach($subcategoria as $sub):
      ...content...
   endforeach;
}
?&gt;
#8

[eluser]Thiago Leao[/eluser]
worked perfectly!!!!
had not thought that way!
thank you so much!




Theme © iAndrew 2016 - Forum software by © MyBB