1
I want to do a query so when I click the button to press more, the LIMIT will increase to show 9 more images in my gallery My Code:
<!-- connect.php -->
<?php
$host = "localhost";
$user = "root";
$db = "fenix";
$pass = "";
try{
$connect = new PDO("mysql:host=$host;dbname=$db",$user,$pass);
}catch(PDOException $e){
die("Error ".$e->getMessage());
}
<!-- index.php -->
<?php
require_once("connect.php");
?>
<script type="text/javascript">
$(document).ready(function(){
$("#carregar_mais").click(function(){
<?php $limite = $limite + 9;?>
});
});
</script>
<?php
$results = $connect->query("SELECT * FROM arquivo ORDER BY id_arquivo DESC LIMIT $limite");
?>
<div class="imagens">
<?php
while($row = $results->fetch(){ ?>
<a href="upload/uploads/<?php echo $row['nome_arquivo'];?>" >
<img class="imagem" src="upload/uploads/<?php echo $row['nome_arquivo'];?>" />
</a>
<?php } ?>
</div>
<center>
<p id="carregar_mais" style="color:white; cursor:pointer;">Carregar mais</p>
<?php echo $limite;?> <!-- Este echo é só para exibir em quanto está meu LIMIT-->
</center>
When loading the page 9 images appear. When I click on "load more" another 9 (18) should appear. It’s like an infinite scroll, but the user decides when to upload more images.
Thank you!
Beware of sql Injection, when using variable
$limite
directly in the query. By the way javascript, it’s not server side, you can’t do it that way. As I was saying, Cole Sear, "I see SQL Injection all the time..."– Ivan Ferrer