Search code examples
phpfancyboximage-gallery

how to put text in while just once php


I have a fancy-box image gallery with a border and each image has if even border-top if odd border-bottom, like this:

enter image description here

And where is the thickest border it is supposed to be text.

I have this code to every picture in the image

<?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);
?>

All the images come from the database. But as you can see there is no text and I don't know what's the problem. Has anyone worked with fancybox? And had this problem?


Solution

  • If you're fetching the text from the same database you're getting the $img from, you can also include the text associated with your image within the while loop. Like this...

    <?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);
    ?>