how to put text in a while in php only once

1

I have an image gallery made with fancybox that all the images that appear come from the database. the gallery is something so .

I have this:

<div id="exterior">
<?php
	$con = mysqli_connect("localhost","root","","gibellino");
	mysqli_set_charset($con,"utf-8");
	$result = mysqli_query($con, "select * from exterior");
	
	$first = 'first';
	echo "<h4>Exterior</h4>";
	
	while($row = mysqli_fetch_array($result)){
		$img = $row['img'];
		echo "
			<a href='images/angel/$img' rel='exterior' title='$img'><img src='images/angel/$img' alt='' id='$first'><span></span></a>
		";
		
		$first = '';
	}
	mysqli_close($con);
	
?>

</div>

and 4 more like divs only changes the id's pretty much. And it looks something like this:

AndIwantedtobeabletoadd%text,butIcannotdoitbecauseifyouputitinsidethewhilealltheimagesappearandyougetoutofthewhileImage.Thatwouldlooklikethis:

    
asked by anonymous 30.11.2015 / 18:34

1 answer

1

This is perhaps more a matter of CSS than of PHP itself.

.pai{
  background:purple;
 }

.pai > .filho {
  background:pink;
  float:left;
  width:calc(100% / 4);
  border:1px solid black;
  box-sizing:border-box;
  height:100px;
  position:relative;
}

.text{
  text-align:center;
  width:100%;
}

.pai > .filho:nth-child(odd) .text{
  position:absolute;
  bottom:0;
}

.pai > .filho:nth-child(even) .text{
  position:absolute;
  top:0;
}
<div class="pai">
  
  <div class="filho">
    <div class="text">Texto</div>
  </div>
      
  <div class="filho">
    <div class="text">Texto</div>
  </div>
      
  <div class="filho">
    <div class="text">Texto</div>
  </div>
      
  <div class="filho">
    <div class="text">Texto</div>
  </div>
      
</div>
    
01.12.2015 / 14:55