如何只输入一次文本 php

how to put text in while just once php

我有一个带边框的花式图片库,每张图片都有偶数上边框或奇数下边框,如下所示:

应该是文本的最粗边框在哪里。

图片中的每张图片我都有这个代码

<?php
 $con = mysqli_connect("localhost","root","","gibellino");
 mysqli_set_charset($con,"utf-8");
 $result = mysqli_query($con, "select * from imper");
     
 $first = 'first';
     
 while($row = mysqli_fetch_array($result)){
  $img = $row['img'];
  echo "<a href='imagem/bd/imper/$img' rel='imper' title='$img'><img src='imagem/bd/imper/$img' alt='' id='$first'><span></span></a>";
  $first = '';
 }
 echo "<h4>Impermeabilização</h4>";
 mysqli_close($con);
?>

所有图片均来自数据库。但是正如您所见,没有文字,我不知道问题出在哪里。有人用过 fancybox 吗?有这个问题吗?

如果您从与 $img 相同的数据库中获取文本,您还可以在 while 循环中包含与图像关联的文本。像这样...

<?php
 $con = mysqli_connect("localhost","root","","gibellino");
 mysqli_set_charset($con,"utf-8");
 $result = mysqli_query($con, "select * from imper");
     
 $first = 'first';
     
 while($row = mysqli_fetch_array($result)){
  $img = $row['img'];
  echo "<a href='imagem/bd/imper/$img' rel='imper' title='$img'><img src='imagem/bd/imper/$img' alt='' id='$first'><span>$some_text</span></a>";
  $first = '';
 }
 echo "<h4>Impermeabilização</h4>";
 mysqli_close($con);
?>