com web/php: Fix counting logic.. as we skip an item if it doesn't exist: images/elephpants.php
| From: | Hannes Magnusson | Date: | Wed, 04 Dec 2013 08:03:32 +0000 |
| Subject: | com web/php: Fix counting logic.. as we skip an item if it doesn't exist: images/elephpants.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-17340@lists.php.net to get a copy of this message | ||
Commit: bcc4cfa62ccc46113e1e47b305156caaa853723c
Author: Hannes Magnusson <bjori@mongodb.com> Wed, 4 Dec 2013 00:03:32 -0800
Parents: 601c8adc8f8ef057b8f55e1e511cc50d4cdadb3b
Branches: master
Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=bcc4cfa62ccc46113e1e47b305156caaa853723c
Log:
Fix counting logic.. as we skip an item if it doesn't exist
Also, don't allow more then 50 pics
Changed paths:
M images/elephpants.php
Diff:
diff --git a/images/elephpants.php b/images/elephpants.php
index 3375f9d..3cee268 100644
--- a/images/elephpants.php
+++ b/images/elephpants.php
@@ -20,7 +20,7 @@
// determine how many images to serve.
if (isset($_REQUEST['count'])) {
- $count = intval($_REQUEST['count']);
+ $count = min(intval($_REQUEST['count']), 50);
} else {
header('HTTP/1.1 400', true, 400);
print json_encode(array(
@@ -46,10 +46,11 @@ if (!$photos || !is_array($photos)) {
// prepare requested number of elephpants at random.
shuffle($photos);
$elephpants = array();
-foreach ($photos as $n => $photo) {
+$got = 0;
+foreach ($photos as $photo) {
// stop when we have the requested number of photos.
- if ($n == $count || $n > 20) {
+ if ($got == $count) {
break;
}
@@ -58,6 +59,7 @@ foreach ($photos as $n => $photo) {
continue;
}
+ $got++;
// add photo to response array.
$elephpants[] = array(
'title' => $photo['title'],
@@ -67,3 +69,4 @@ foreach ($photos as $n => $photo) {
}
print json_encode($elephpants);
+