Welcome Guest, Not a member yet? Register   Sign In
$query->mysql_num_rows >
#1

[eluser]Asinox[/eluser]
Hi, i hav a question please, i want to do something like that:
Code:
<?php

if($query ->mysql_nums_row()>0):
  foreach .....

  // display register

  endforeach;

endif;
?>

but with my model and my controller i cant do that... im new with this and maybe im lost...

the function for get the comments of some articles is get_comentarios($id)
here my controller and my model
Code:
class Periodico extends Controller{
        function Periodico(){ // constructor
            parent::Controller();
            $this->load->helper('url');
            $this->load->helper('form');
        }
        
        function index(){ //index lo mismo que decir index.php
            $data['titulo_site'] = "Paso a Paso Online | Bienvenido";
            /*$this->load->model('articulos/articulos_model');
            $data['query'] = $this->articulos_model->get_articulos();
            $this->load->view('articulos/articulos_view',$data);*/
            $this->articulos();

        }
        
        function articulos(){
            $this->load->model('articulos/articulos_model');
            $data['query'] = $this->articulos_model->get_articulos();
            $this->load->view('articulos/articulos_view',$data);
        }
            
        function leer($id){
            $data['titulo_site'] = "Paso a Paso Online";
            $this->load->model('articulos/articulos_model');
            $data['query'] = $this->articulos_model->get_articulo($id);
            $this->load->view('articulos/leer_view',$data);
        }
        
        function get_comentarios($id){
            $this->load->model('articulos/articulos_model');
            $data['query'] = $this->articulos_model->get_comentarios($id);
            $this->load->view('articulos/leer_view',$data);
        }
        
        function agregar_comentarios(){
            $this->db->insert('comments',$_POST);
            redirect('periodico/leer/'.$_POST['article_id']);
            
        }
    
}

Which variable i need to use for do the $query->mysql_nums_rows ???

model
Code:
class Articulos_model extends Model{
        function Articulos_model(){
            parent::Model();
        }
        
        function get_articulos(){
            $this->load->database();
            $query = $this->db->get('articles');
            return $query->result();
        }
        
        function get_articulo($id){
            $this->load->database();
            $query = $this->db->getwhere('articles',array('id'=>$id));
            return $query->row_array();
        }
        function get_comentarios($id){
            $this->load->database();
            $query= $this->db->getwhere('comments',array('article_id'=>$id));
            return $query->row_array();
        }
    }


im lost...with do the if($query->mysql_nums_row >0) , im trying to get all comments from comments table in the article id....


sorry by my english...

thanks
#2

[eluser]mglinski[/eluser]
To get the number of rows of a query, after you execute the query do this:
Code:
$num = $query->num_rows()
-Matt




Theme © iAndrew 2016 - Forum software by © MyBB