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

[eluser]Thiago Leao[/eluser]
categoria_model

Code:
<?php
class Categoria_model extends Model{
    
    function listar($id_category, $maximo, $inicio){        
        //$query = $this->db->get_where('products', array('id_category' => $id_category), $maximo, $inicio);
        //return $query->result();    
        
        $this->db->select('*');
        $this->db->from('products');
        $this->db->join('pictures', 'pictures.id_products = products.id_products');
        $this->db->where('id_category', $id_category);
        $this->db->limit($inicio, $maximo);
        
        $query = $this->db->get();
        
        echo print_r($query);
    }
    
    function contaRegistros(){
           return $this->db->count_all_results('products');
    }
    
}
?>

categoria CONTROLLER

Code:
<?php
class Categoria extends Controller{
    
    function __construct(){
        parent::Controller();    
    }
    
    function index($id_category){
        $dados['titulo'] = 'Catalogo Collection - Sua coleção Online!';
        $this->load->library('pagination');
        $this->load->model('categoria_model');
        
        $maximo = 20;
        $inicio = $this->uri->segment(4,0);

        $config['base_url'] = base_url() .'categoria/index/';
        $config['uri_segment'] = 4;
        $config['total_rows'] = $this->categoria_model->contaRegistros();
        $config['per_page'] = $maximo;
    
        $this->pagination->initialize($config);
    
        $dados['paginacao'] =  $this->pagination->create_links();        
        $dados['listar_category'] = $this->categoria_model->listar($id_category, $maximo, $inicio);
        
        $this->load->model('home_model');
        $dados['last_member'] = $this->home_model->listar_members();
        $dados['categorys'] = $this->home_model->listar_category();
        
        $this->load->view('categoria', $dados);
    }
    
}
?>

VIEW

Code:
<div id="ver_categorias">
        <ul>
            &lt;?php foreach($listar_category as $listar): ?&gt;
            <li><a href="#">&lt;?=$listar->personagem;?&gt;</a></li>
            &lt;?php endforeach; ?&gt;
        </ul>
      </div>

ERROR

CI_DB_mysql_result Object ( [conn_id] => Resource id #31 [result_id] => Resource id #44 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 0 [row_data] => ) 1
#2

[eluser]cahva[/eluser]
You're not returning it. Use:
Code:
$query = $this->db->get();
return $query->result();
#3

[eluser]Thiago Leao[/eluser]
does not appear nothing, no error!
#4

[eluser]missionsix[/eluser]
Code:
echo print_r($query);

will print the result resource object. If you wish to get your collection, you need to use

Code:
$query = $this->db->get();
        
return $query->result();

Which will return a collection of your results in object form. Use
Code:
return $query->result_array();

To get results in array form. You would then iterate over your result in the view.
#5

[eluser]Thiago Leao[/eluser]
Still not showing anything!!
=/
Code:
$query = $this->db->get();
return $query->result_array();
#6

[eluser]Thiago Leao[/eluser]
anyone help?
please!
thanks
#7

[eluser]Ochetski[/eluser]
You must take care with your tests:
Code:
echo print_r($query);
must be:
Code:
return $query;

And here $listar_category is a sql query resource, you must transform it with ->result() like this:

Code:
&lt;?php foreach($listar_category->result() as $listar): ?&gt;
<li><a href="#">&lt;?=$listar->personagem;?&gt;</a></li>
&lt;?php endforeach; ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB