Codeigniter - Search Mysql and show registration amount

Asked

Viewed 59 times

-1

Dear friends.

I am mounting a routine in Codeigniter and would like to do a search in Mysql and show on screen to the user, how many images have been attached to the property.

For example: (Total: 5 of 20) === > in a total of 20 images has already been attached 05 and missing 15 to be attached.

How do I do this research using Codeigniter ?

Note: using only (normal) PHP with you, but with Codeigniter, I’m facing this problem.

Someone would have some example of that part.

Grateful,

Cesar

  • How would you use "normal PHP"?

2 answers

1

You can use the

$this->db->count_all('nome_tabela');

or Voce can do a Count in its result

count($query->result());

0

Dear friend greetings...

I did it like this in the Modell folder:

    //Soma a quantidade de imagens por imóvel
    public function count_anexos($id){
        $sql = "SELECT an.idAnexos, an.imoveis_idImoveis, im.idImoveis, COUNT(an.imoveis_idImoveis) AS total
                  FROM imoveis im
            INNER JOIN anexos an ON an.imoveis_idImoveis = im.idImoveis
                 WHERE an.imoveis_idImoveis = '$id' ";
        $result = $this->db->query($sql);
        return $result->row()->total;
    }   

the problem is that when I include or delete an image, the total does not update, if I do not press F5.

I wish I could update automatically.

Grateful,

Cesar

  • A then in this case you need to use ajax requests with java script, a searched on.

Browser other questions tagged

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