Preciso urgente que a exibição de uma consulta de um banco de dados seja sob demanda. Tenho os seguintes códigos, sendo que o Javascript estou tentando adaptar ao PHP já existente.
javascript dentro da página php
//Carrega um conteúdo inicial ao carregar a página
$(function () {
num_posts_show = 3;
speed_to_top = 1000; // in ms
$(".post").slice(0, num_posts_show).show();
$("#loadmore").on('click', function (e) {
e.preventDefault();
$("div:hidden").slice(0, num_posts_show).slideDown();
if ($("div:hidden").length == 0) {
$("#load").fadeOut('slow');
}
$('html,body').animate({
scrollTop: $(this).offset().top
}, 1500);
});
});
$('#totop').click(function () {
$('body,html').animate({
scrollTop: 0
}, speed_to_top);
return false;
});
$(window).scroll(function () {
if ($(this).scrollTop() > 50) {
$('#totop').fadeIn();
} else {
$('#totop').fadeOut();
}
});
restante da página em PHP
SEI QUE O 10 DA LINHA SEGUINTE EXIBE 10 RESULTADOS, GOSTARIA DE AO MENOS ALTERAR DINAMICAMENTE ESSE VALOR SEM REFRESH NA PÁGINA.
SEI QUE MYSQL_QUERY ESTÁ DEPRECIADA, MAS ESSA ALTERAÇÃO OCORRERÁ DEPOIS.
<div style="display:none;height:36px;" class="tips"><?=__FILE__?></div>
<?php
//SEI QUE O 10 DA LINHA SEGUINTE EXIBE 10 RESULTADOS, GOSTARIA DE AO MENOS ALTERAR DINAMICAMENTE ESSE VALOR SEM REFRESH NA PÁGINA.
$limite = empty($INI['system']['limite_vitrine']) ? 10: (int) $INI['system']['limite_vitrine'];
$ordem = 'rand()';
$sql = "select * from team where ehdestaque = 'Y' and (status is null or status = 1) and (pago = 'sim' or anunciogratis = 's') and begin_time < '".time()."' and end_time > '".time()."' order by " . $ordem . " limit " . $limite;
$rs = mysql_query($sql);
if(mysql_num_rows($rs)){
?>
<div class="destaquesMobile">
<?php
while($l = mysql_fetch_assoc($rs)){
$l['title'] = utf8_decode($l['title']);
$link = $ROOTPATH . "/?idoferta=" . $l['id'];
if($l['imgdestaque'] !=""){
$imagemoferta = $INI['system']['wwwprefix']."/media/".$l['image']; //ESTA LINHA ESTAVA NO ELSE
}
else{
$imagemoferta = getImagemDestaque($l['imgdestaque']); //ESTA LINHA ESTAVA NO IF
}
if(!(empty($l["maximo_hospede"]))) {
$hospedes = "Total de hóspedes: " . $l["maximo_hospede"];
}
if(!(empty($l["team_price"]))) {
$valordiaria = "Valor: R$ " . number_format($l["team_price"],2,",",".");
}
if(!(empty($l["imob_tipo"]))) {
$sqlT = "select nome from tipoimoveis where id = '" . $l["imob_tipo"] . "'";
$rsT = mysql_query($sqlT);
$tipo = mysql_fetch_assoc($rsT);
}
else {
$bairro = utf8_decode("Bairro não informado.");
}
$l['title'] = $l['title'];
?>
<div class="itemMobile post">
<div id="caption_mobile" class="caption_mobile" style="background-color: #f9f6f7;"><?=$l['title']?></div>
<figure class="boxFigureMobile">
<p class="boxContentText"> <?=displaySubStringWithStrip($l['title'], 30)?> </p>
<a href="<?=$link?>">
<img src="<?=$imagemoferta?>" alt="<?=$l['title']?>" title="<?=$l['title']?>">
</a>
</figure>
<div class="boxContentMobile">
<p class="boxContentNormal"><?php echo "Imóvel: " . utf8_decode($tipo["nome"]); ?></p>
<p class="boxContentNormal"><?php echo $valordiaria; ?></p>
<p class="boxContentNormal"><?php echo $hospedes; ?></p>
<div id="box_redes_sociais">
<img id="share_redes_sociais" class="boxContentNormal" src="http://www.balcaodeservico.com.br/skin/padrão/images/icon_facebook.png"/>
<img id="share_redes_sociais" class="boxContentNormal" src="http://www.balcaodeservico.com.br/skin/padrão/images/icon_instagram.png"/>
<img id="share_redes_sociais" class="boxContentNormal" src="http://www.balcaodeservico.com.br/skin/padrão/images/icon_twitter.png"/>
<img id="share_redes_sociais" class="boxContentNormal" src="http://www.balcaodeservico.com.br/skin/padrão/images/icon_whatsapp.png"/>
</div>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
<a href="#" id="loadmore">Carregar mais...</a>
<a href="#" id="totop">Ir para o topo</a>