I have the following problem, I make a select in the database and display the images on the page, it is a classified portal where the person makes an ad and can upload up to 10 images .
So far so good, I get the ad and it is displayed on the page, the problem is that it is displaying the ad the same amount of times it had to upload image.
If the ad has 5 photos it is displayed 5 times, if it has an exhibit once. What can I do to print only the first item in the 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 looks 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 pullAThumb ($ id) { $ this-> db-> where ("idPost", $ id); return $ this-> db-> get ("snapshots") -> row_array ();
}