简体   繁体   English

我如何在jQuery和PHP的while循环中限制结果

[英]How do i limit results in a while loop with jQuery and PHP

I didn't really know how to set up the question without making it extremely long, so I will explain the thick of it in here. 我真的不知道如何在不把问题弄得太长的情况下提出这个问题,因此在这里我将详细解释。

Basically my code is pulling images from a directory on another server. 基本上,我的代码是从另一台服务器上的目录中提取图像。 I am using a jQuery pagination script I found online. 我正在使用在网上找到的jQuery分页脚本。 The script works, but only after every single image loads on the page (there are a lot of images, so it takes a while to load). 该脚本有效,但仅在页面上加载每张图像之后(图像很多,因此加载需要一段时间)。

What I'm wanting to accomplish is basically being able to load the page quickly by only showing 36 results at a time. 我要完成的工作基本上是能够一次只显示36个结果来快速加载页面。 I'd like the jQuery pagination to work, but what'd be even more ideal is just loading is as you scroll down. 我希望jQuery分页能够正常工作,但更理想的是在向下滚动时加载。 I've tried using a few different endless scrolling scripts on this, but for some reason it never works properly. 我曾尝试在此上使用一些不同的无尽滚动脚本,但由于某些原因,它永远无法正常工作。

Hopefully I'm making it very clear on what I'm trying to do. 希望我能很清楚地说明我要做什么。

Here is the link to the page: http://habbolicious.com/v2/testing.php 这是页面的链接: http : //habbolicious.com/v2/testing.php

...and here is the code: ...这是代码:

    <head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.pages.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $("div.holder").jPages({
        containerID : "test",
        perPage: 36
      });
});
</script>
</head>

<div class="holder"></div>
<div id="test">

<?php
$url = "http://habbo.it/gamedata/external_flash_texts/0";
$data = file_get_contents($url);
$newlines = array("\n" ,"\r", "\r\n", ">", "<", "/");
$content = str_replace($newlines, "", html_entity_decode($data));

$Statushtml= '/badge_desc_(.+?)=/';
preg_match_all($Statushtml,$content,$Statusraw);
$badges = implode("-", $Statusraw[0]);
$badgevar = explode("=-badge_desc_", $badges);
$number = ($badgevar);
$badgevar2 = str_replace("=","",$badgevar);
$badgevar3 = str_replace("badge_desc_","",$badgevar2);
$number = count($badgevar3);
while ($number != 0) { ?> 

<script>
$("img").error(function () { 
    $(this).parent().css({display:"none"}); 
});
</script>

<?php

$number = $number - 1; ?>

<?php
$imageUrl = "http://images.habbo.it/c_images/album1584/$badgevar3[$number].gif";
echo '<div class="derpy" style="width:10%; height:70px; line-height:10px; overflow:hidden; border-radius:5px; background:#eaeaea; color:#585858; float:left; margin:5px; padding:10px; text-align:center;"><img class="lazy" src="' . $imageUrl . '" onerror="this.style.display=none" /><br/>' . $badgevar3[$number] . '</div>';
if(file_exists($imageUrl))
{

} else {

}
}
?>

<div style="clear:both;"></div>

</div>

in your script: $number = count( * *); 在您的脚本中:$ number = count( * *);

and the 'while' make a countdown for the $number to the 0. 而“ while”则将$ number倒数为0。

if you want only 36 pictures, then you need the line 10 "$number = 36;" 如果只需要36张图片,则需要10行“ $ number = 36;”。 , instead of "$number = ($badgevar);" ,而不是“ $ number =($ badgevar);”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM