1
I’m in the following problem, I make one select in the database and display the images on the page, is a classified portal where the person makes an ad and can upload up to 10 images.
So far so good, I picked up the ad and it is displayed on the page, the problem that it is displaying the ad the same amount of times that it had image upload.
If the ad has 5 photos it displays 5 times, if it has one it displays once. What can I do for him to print only the first item of array?
class Carroshome extends CI_Model
{
public function exibeCarrosHome($limit =0,$offset =0){
if ($limit > 0) $this->db->limit($limit,$offset);
$this->db->select("*");
$this->db->from("anuncios");
$this->db->join("fotosanuncios", "anuncios.id = fotosanuncios.idPost");
$this->db->order_by('id', 'DESC');
return $valida = $this->db->get()->result_array();
}
public function totalLinhas(){
return $this->db->count_all("anuncios");
}
}
My foreach is like this.
<div class="col s12 m6 l6 carrosRetangulo">
<div class="col s12 m12 l12 carrosBanner">
<div class="fundoFoto">
<a href="<?= base_url("car/$dado[id]") ?>" style="padding: 0 !important; margin: 0 !important; border:none !important;background: transparent !important;">
<img src="<?= base_url("$dado[caminho]thumb/$dado[thumb]") ?>" class="carrosFotomini" alt="">
</a>
</div>
<div class="detalhesCarro">
<ul class="itensCarroFront">
<li>Model : <?= substr($dado['modelo'],0,15) ?></li>
<li>State : <?= $dado['stateAuto'] ?></li>
<li>Year : <?= $dado['year'] ?></li>
<li>Miles : <?= $dado['odometer'] ?></li>
<li>Fuel : <?= $dado['fuel'] ?></li>
<li>Transmission : <?= $dado['transmission'] ?></li>
</ul>
</div>
<div class="precoCarro"><span class="precoVertical"><?= ($dado['price'])? numeroEmReais($dado['price']) : "check" ?></span></div>
</div>
</div>
<?php endforeach; ?>
Solved with Jonathan’s help
public Function puxaThumb($id){ $this->db->Where("idPost",$id); Return $this->db->get("photofunctions")->row_array();
}
Thank you Jonathan, I understood what I should do, I will create a function receiving an id and it makes a selection of the first line you find in the bank. Thank you very much, I don’t know how I didn’t think of it before, I’m working many hrs a day on this project and I think I’m bugging Rs.
– Bruno Luiz
Thanks, solved my problem. Follows model code. public Function puxaThumb($id){ $this->db->Where("idPost",$id); Return $this->db->get("fotosanuncios")->row_array(); }
– Bruno Luiz