Welcome Guest, Not a member yet? Register   Sign In
Get a query with a limit and offset and see if a result belongs to that
#1

[eluser]FabioAntunes[/eluser]
Hi there I'm struggling here with this little problem.

I have a pagination that shows 10 results each time,(10 student classes), what I want to do is instead of beginning in page 1 show as default the page that somewhere in that 10 results has the id of a student class.

Code:
$idClassRoom= 100;

$this->db->start_cache();
$this->db->select(etc);
$this->db->from(etc);
$this->db->stop_cache();
$offset = 0;

do{
$this->db->limit(10, $offset);
//I have something missing here so this can work, I want to know if $idClassRoom belongs //to this 10 results
//case it's true, I break off the do while and save the offset so I can build my //pagination and the default page it will be the offset and not page one.
$query = $this->db->get();
  
//case the $idClassRoom doesn't belong to the 10 results I increase offset
$offset += 10;
}while(//result);

I hope I made myself clear
#2

[eluser]weboap[/eluser]
check this tutorial for a CI pagination example

http://net.tutsplus.com/articles/news/co...agination/

#3

[eluser]FabioAntunes[/eluser]
[quote author="weboap" date="1338576162"]check this tutorial for a CI pagination example

http://net.tutsplus.com/articles/news/co...agination/

[/quote]

But I already have a pagination working, that didn't help nothing at all.

I just want to know if there's a way to "query a query" with active records:


I'll try to explain myself again, I have this query wich has a limit of 10 results

Code:
$this->db->start_cache();
$this->db->select(etc);
$this->db->from(etc);
$this->db->stop_cache();

And I cached it, so i can apply the limit and after applying the limit I want to verify if in that 10 results I limited there is the idClassroom I wanted


I can solve the problem this way
Code:
$this->db->start_cache();
$this->db->select(etc);
$this->db->from(etc);
$this->db->stop_cache();
$offset = 0;
$bool = false;
$idClassRoom = 100;

do{
  
$this->db->limit($num, $offset);
$query = $this->db->get();
  
foreach ($query->result_array() as  $row){
if($row['id_classroom'] == $idClassRoom){
$bool = true;
break;
}
    
}
$offset += 10;
}while($bool);
  
$this->db->flush_cache();

return $query;

I just want to know if there's a better way.




Theme © iAndrew 2016 - Forum software by © MyBB