Jump to content
guarana1

[Resolvido] Lentidao... :(

Recommended Posts

guarana1

Boas, estou a usar a seguinte galeria no meu site http://play.equiet.sk/gallery-masonry.html

E para buscar as imagens uso este loop:

<?php

foreach(glob('blah/'.'*') as $filename) {
echo "
  <li class='masonry-brick' style='position: absolute; top: 0px; left: 0px;'>
	<a href='portfolio-item.php?filename=$filename' class='photo' rel='gallery'>
	<img src='".$filename."' alt=''>
	<p class='caption'>Lorem ipsum dolor</p>
	</a>
 </li>
 ";  }

?>

O codigo original da galeria em html estava assim

<li class="masonry-brick" style="position: absolute; top: 0px; left: 0px;">
<a href="placeholders/960/1.jpg" class="photo" rel="gallery">
  <img src="http://play.equiet.sk/placeholders/360/1.jpg" alt="">
  <p class="caption">Lorem ipsum dolor</p>
</a>
 </li>

Quando meto mais de 10 imagens, aquilo fica bastante lento, fica tudo "lagado" a usar o scroll down ou a passar com o rato em cima. E uma tristeza :(

Sera que e por causa do loop?

Quando tiro o loop e meto tudo manualmente fica como deve de ser.

Edited by Rui Carlos

Share this post


Link to post
Share on other sites
guarana1

guarda antes o endereço das imagens na bd, e faz loop á query ;)

Uhm, estou a ter umas dificuldades no codigo.

<?php
$shots = mysql_query("SELECT nome FROM galeria") or die(mysql_error());

while($row=mysql_fetch_array($shots))
$data[]=$row;


foreach($shots as $data)  {

echo "
 <li>

  <li class='masonry-brick' style='position: absolute; top: 0px; left: 0px;'>
    <a href='portfolio-item.php?filename=$filename' class='photo' rel='gallery'>
      <img src='".$shots."' alt=''>
<p class='caption'>Lorem ipsum dolor</p>





   </a>
 </li>
 "; }

?>     

aparece isto

"invalid argument supplied for each()"

o nome na bd contem a diretoria da imagem, assim: "blah/animal_0010.jpg"

Share this post


Link to post
Share on other sites
guarana1

Uhm, estou a ter umas dificuldades no codigo.

<?php
$shots = mysql_query("SELECT nome FROM galeria") or die(mysql_error());

while($row=mysql_fetch_array($shots))
$data[]=$row;


foreach($shots as $data)  {

echo "
 <li>

  <li class='masonry-brick' style='position: absolute; top: 0px; left: 0px;'>
 <a href='portfolio-item.php?filename=$filename' class='photo' rel='gallery'>
   <img src='".$shots."' alt=''>
<p class='caption'>Lorem ipsum dolor</p>





</a>
 </li>
 "; }

?>	

aparece isto

"invalid argument supplied for each()"

o nome na bd contem a diretoria da imagem, assim: "blah/animal_0010.jpg"

Reparei que se usasse imagens mais pequenas, em vez de imagens tipo 1920*1200 fica bastante mais rapido... deve ser esse o problema da lentidao.

Share this post


Link to post
Share on other sites
I-NOZex

tens o foreach mal

o foreach é:

foreach($array as $item) //certo

e tu tens:

foreach($item as $array) //errado

mas sim, se as imagens sao muito grandes, poderá ser um problema, deve-se usar sempre imagens a escala do tamanho onde sao apresentadas...

Edited by I-NOZex

B2R » Beat2Revolution v3.0b | Regista e divulga-nos

beat2revolution.net

Share this post


Link to post
Share on other sites
guarana1

Acabei de fazer desta maneira, obrigado pela ajuda. :thumbsup:

<?php
$query_select = "SELECT * FROM galeria;";
$result_select = mysql_query($query_select) or die(mysql_error());
$rows = array();
while($row = mysql_fetch_array($result_select))
   $rows[] = $row;
foreach($rows as $row){
   $shots = stripslashes($row['nome']);
   {

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.