How to show all the contents of a database in HTML?

0

Good I need to know how I do that the url lodged in my Database can extract them with php and place them in the "src" of the images so that they always load. You will see I have the following problem, I am doing a social network as a degree project, obviously not complete, but if some functions, I have a week left, and I need to create a gallery with PHP mysqli AJAX, and I can already host the url of the photos in the database, but I can not get those url for a query "fetch_assoc" and print a label "" for each url that has the database, really that's what I want.

I leave the codes to help me better.

PS: I'm a newbie in PHP.

<?php 
    session_start();
    $usuario = $_SESSION['usuario'];

    if (isset($_POST['upload'])) {
	    $conexion = mysqli_connect("localhost", "root", "","imagen"); 
	    if (!$conexion) { 
			die("Fallo la conexión a la Base de Datos: " . mysql_error()); 
	    }else{
		$imgAlbum = "tmpAlbums/"; 
		$archivo = $_FILES['fl_album']['tmp_name'];
		$nombrearchivo = $_FILES['fl_album']['name']; 

		move_uploaded_file($archivo, $imgAlbum."/".$nombrearchivo); 

		$imgAlbum = $imgAlbum."/".$nombrearchivo;
		$saveIMG = mysqli_query($conexion,"INSERT INTO imagephp VALUES('".$imgAlbum."')");
	    }      			
    }
?>

<div class="albumes">
			<img src="<?php echo ($imgAlbum); ?>" alt="">
			<?php     							
				$selectURL = mysqli_query($conexion, "SELECT URL_img FROM imagephp");
				while ($url = mysqli_fetch_assoc($selectURL)) {
					echo "<img src='$url'/>";
				}
				var_dump($url);
			 ?>
		</div>

I am ignoring a sea of code because it is obvious that you know and understand what it would take, like body etc, but what is there is because it is the only thing I want to be helped in that.

I thank you in advance and I ask you please understand that they speak with a newbie ...:)

    
asked by Abdiel 07.12.2018 в 01:15
source

1 answer

0

The variable $url has an array of objects, you can not tell the src of the image that your route is an array, you have to take the route of that array, in this case the field URL_img

$selectURL = mysqli_query($conexion, "SELECT URL_img FROM imagephp");
while ($url = mysqli_fetch_assoc($selectURL) ) {
  echo "<img src='".$url['URL_img ']."'/>";
}
    
answered by 07.12.2018 / 01:23
source