Error limit Codeigniter

Asked

Viewed 94 times

0

Hello everyone from Codeigniter Brasil, I have a query that returns everything perfect in localhost but the server does not return the way it was written.

It is to return 6 results but on the server returns the amount he finds best up to 6.

$this->db->limit(6);
$this->db->select("*");
$this->db->from("vips");
$this->db->join("anuncios", "anuncios.id = vips.idPostVip");
$this->db->order_by('RAND()');
return $this->db->get()->result_array();

Any hint ?

Some configuration of PHP ?

Help me Rs.

Thank you.

  • what is the expected result with this code, how many records should return?

  • Should return 3 results.

  • 1

    Then the limit it is respecting if behind 1, 2 or 3. It should be this vip Where > 0. Check the data. Should not be attending the Where.

  • Hello, so the server has many Vips posts, it pulls only Vips but does not bring back the 3 I need. This is what I’m not getting.

  • I would put the limit line after the order_by, but I don’t know if that’s the problem.

  • 1

    @Brunoluiz already tried to pull the line $this->db->where("vip > ",0); to see if it works?

  • I’ve taken and remains the same.

  • Poxa then needs to see the whole process to be sure of what is happening ... even complicated

  • What makes me not understand is that I only have the model, I pull the Controller and I show it in the View, there’s nothing else. Do you have another way to do Random without order by ?

  • Yes, there is! .... ....

  • This post was not answered here and was not answered here. They keep putting that my post was solved here but it was not, the answers were wrong and I continue with the problem.

  • When you run this query directly in the database (via phpmyadmin) of the production server comes 6 records?

Show 7 more comments

1 answer

1

Use in this way:

public function exibeSugestaoHome()
{
    $this->db->limit(3);
    $this->db->select("*");
    $this->db->from("anuncios");
    $this->db->where("vip > ",0);
    $this->db->order_by('RAND()');
    return $this->db->get()->result_array();
}

can be done as well by shuffling items by the function of the , shuffle:

public function exibeSugestaoHome()
{
    $this->db->limit(3);
    $this->db->select("*");
    $this->db->from("anuncios");
    $this->db->where("vip > ",0);
    $result = $this->db->get()->result_array();
    shuffle($result);
    return $result;
}

the difference of the forms presented that the first shuffles the items directly in the table, and the second only in the results obtained. Depending on the situation one of them fits.

  • Worse than I just realized it didn’t work, the last option pulls all three and scrambles only. I need to pull random items from the bench to not keep repeating.

  • 1

    Truth @Brunoluiz the last one he takes the 3 and generates a shuffle of these items, the first one generates the shuffle in the table data. Maybe there is something in your table that is causing or in SQL that is not bringing the 3 items, have to see the background.

  • So in the bank the vip option is 0 or 1.

  • @Brunoluiz, then remove that line $this->db->where("vip > ",0); does not make sense or worse do not recommend $this->db->where("vip >= ",0); which is the same as the first

  • But this field I can only pull the cars that are sponsored on the site, there I mark them as sponsored "vip" or not.

  • @Brunoluiz se vip is equal = 1 place $this->db->where("vip",1); or the corresponding value?

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.