Welcome Guest, Not a member yet? Register   Sign In
Query not showing all the rows
#1
Question 

Hi, I'm using the last current version of C.I, and I having a wierd problem with a query.

I'm doing this query:

PHP Code:
public function get_event(){
    
$query $this->db->query("SELECT id,date_register FROM log_event ORDER BY id DESC");
    return 
$query->num_rows();


it show me "72" but in the table log_event I have 172 rows

if I paste the same query in MYSQL Workbench, it shows me 172 rows, what I'm doing wrong?
is there some limit in the C.I queries?
Reply
#2

(This post was last modified: 09-23-2015, 07:26 AM by DEV03-ROMAIN.)

(09-22-2015, 10:57 PM)gepd Wrote: Hi, I'm using the last current version of C.I, and I having a wierd problem with a query.

I'm doing this query:



PHP Code:
public function get_event(){
 
$query $this->db->query("SELECT id,date_register FROM log_event ORDER BY id DESC");
 return 
$query->num_rows();


it show me "72" but in the table log_event I have 172 rows

if I paste the same query in MYSQL Workbench, it shows me 172 rows, what I'm doing wrong?
is there some limit in the C.I queries?

you could try this instead of num_rows()



PHP Code:
count_all_results(); 
Edit :
Quote:it show me "72" but in the table log_event I have 172 rows

looks like you just missing the " 1" ... maybe variable type problems. Can we see full code of your problem ?  
Reply
#3

Thanks for your answer DEV03-ROMAIN, I already tried with with something else than
Code:
num_rows()

but it's the same result

there is the full code:
Model
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
date_default_timezone_set("UTC");

class History_model extends CI_Model {
    public function get_logs(){
        $query = $this->db->query("SELECT id,date_register FROM log_event ORDER BY id DESC");
        $total = $query->num_rows();

        $json  = array("total_logs"=>$total);            
        foreach ($query->result_array() as $row){                
            $json["datails"][] = array("id"=>$row["id"],"date"=>date_format(date_create($row['date_register']),"d/m/Y H:i:s"));
        }
        return $json;
    }
}

and this is the controller
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');


class Jsondata extends CI_Controller {
    public function logs(){
        echo json_encode($this->history_model->get_logs());
    }
}

I know there is an error, be cause I can see only 72 rows, and I already check the db, the data is there.
Reply
#4

I would start by breaking down your query to see if you get different results.
PHP Code:
$this->db->query("SELECT * FROM log_event"); // Start here and keep building up to what you want

$this->db->query("SELECT id,date_register FROM log_event");

$this->db->query("SELECT id,date_register FROM log_event ORDER BY id DESC"); 
Reply
#5

(09-23-2015, 11:02 AM)gepd Wrote: Thanks for your answer DEV03-ROMAIN, I already tried with with something else than




Code:
num_rows()

but it's the same  result

there is the full code:
Model




Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
date_default_timezone_set("UTC");

class History_model extends CI_Model {
public function get_logs(){
$query = $this->db->query("SELECT id,date_register FROM log_event ORDER BY id DESC");
$total = $query->num_rows();

$json  = array("total_logs"=>$total);
foreach ($query->result_array() as $row){
$json["datails"][] = array("id"=>$row["id"],"date"=>date_format(date_create($row['date_register']),"d/m/Y H:i:s"));
}
return $json;
}
}

and this is the controller




Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');


class Jsondata extends CI_Controller {
public function logs(){
echo json_encode($this->history_model->get_logs());
}
}

I know there is an error, be cause I can see only 72 rows, and I already check the db, the data is there.

hmmm, your code seems to be ok for me.

Do you have the 172 rows in $json["datails"] ?

Did you try doing 
echo $query -> num_rows(); 

just after $query -> result();
Reply




Theme © iAndrew 2016 - Forum software by © MyBB