How to For loop for every 50th number start to end point in PHP
up vote
-1
down vote
favorite
I want For loop to get every 50th number whenever we click next or previous it will get 50+ or 50-
Here's my code
<?php
$startpage=1;
$endpage=3;
for($p=$startpage;$p<=$endpage;$p++)
echo file_get_html("mysite.com/mypage.php?offset=$p"); // shows offset=1, offset=2, offset=3
//But I want to get offset for 50+ or 50- when click next or previous button
$startpage=0;
$endpage=200;
for($p=$startpage;$p<=$endpage;$p++)
echo file_get_html("mysite.com/mypage.php?offset=$p"); // it will work like offset=0, offset=50, offset=100, offset=150, offset=200
?>
php pagination
add a comment |
up vote
-1
down vote
favorite
I want For loop to get every 50th number whenever we click next or previous it will get 50+ or 50-
Here's my code
<?php
$startpage=1;
$endpage=3;
for($p=$startpage;$p<=$endpage;$p++)
echo file_get_html("mysite.com/mypage.php?offset=$p"); // shows offset=1, offset=2, offset=3
//But I want to get offset for 50+ or 50- when click next or previous button
$startpage=0;
$endpage=200;
for($p=$startpage;$p<=$endpage;$p++)
echo file_get_html("mysite.com/mypage.php?offset=$p"); // it will work like offset=0, offset=50, offset=100, offset=150, offset=200
?>
php pagination
Not sure what the "it will work like" comment means.
– cellepo
Nov 11 at 20:01
The one Answer here (as of commenting now) is correct - but in general, even though this focuses on PHP, this question touches on the general idea of "loop guard" that is common to most languages in general. Learning more about loop guards in general sounds like it would be helpful for you.
– cellepo
Nov 11 at 20:06
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I want For loop to get every 50th number whenever we click next or previous it will get 50+ or 50-
Here's my code
<?php
$startpage=1;
$endpage=3;
for($p=$startpage;$p<=$endpage;$p++)
echo file_get_html("mysite.com/mypage.php?offset=$p"); // shows offset=1, offset=2, offset=3
//But I want to get offset for 50+ or 50- when click next or previous button
$startpage=0;
$endpage=200;
for($p=$startpage;$p<=$endpage;$p++)
echo file_get_html("mysite.com/mypage.php?offset=$p"); // it will work like offset=0, offset=50, offset=100, offset=150, offset=200
?>
php pagination
I want For loop to get every 50th number whenever we click next or previous it will get 50+ or 50-
Here's my code
<?php
$startpage=1;
$endpage=3;
for($p=$startpage;$p<=$endpage;$p++)
echo file_get_html("mysite.com/mypage.php?offset=$p"); // shows offset=1, offset=2, offset=3
//But I want to get offset for 50+ or 50- when click next or previous button
$startpage=0;
$endpage=200;
for($p=$startpage;$p<=$endpage;$p++)
echo file_get_html("mysite.com/mypage.php?offset=$p"); // it will work like offset=0, offset=50, offset=100, offset=150, offset=200
?>
php pagination
php pagination
asked Nov 11 at 19:13
Ken
217
217
Not sure what the "it will work like" comment means.
– cellepo
Nov 11 at 20:01
The one Answer here (as of commenting now) is correct - but in general, even though this focuses on PHP, this question touches on the general idea of "loop guard" that is common to most languages in general. Learning more about loop guards in general sounds like it would be helpful for you.
– cellepo
Nov 11 at 20:06
add a comment |
Not sure what the "it will work like" comment means.
– cellepo
Nov 11 at 20:01
The one Answer here (as of commenting now) is correct - but in general, even though this focuses on PHP, this question touches on the general idea of "loop guard" that is common to most languages in general. Learning more about loop guards in general sounds like it would be helpful for you.
– cellepo
Nov 11 at 20:06
Not sure what the "it will work like" comment means.
– cellepo
Nov 11 at 20:01
Not sure what the "it will work like" comment means.
– cellepo
Nov 11 at 20:01
The one Answer here (as of commenting now) is correct - but in general, even though this focuses on PHP, this question touches on the general idea of "loop guard" that is common to most languages in general. Learning more about loop guards in general sounds like it would be helpful for you.
– cellepo
Nov 11 at 20:06
The one Answer here (as of commenting now) is correct - but in general, even though this focuses on PHP, this question touches on the general idea of "loop guard" that is common to most languages in general. Learning more about loop guards in general sounds like it would be helpful for you.
– cellepo
Nov 11 at 20:06
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
use $p+=50
instead of $p++
for($p=$startpage;$p<=$endpage;$p+=50)
echo file_get_html("mysite.com/mypage.php?offset=$p"); // it will work like offset=0, offset=50, offset=100, offset=150, offset=200
All additionally just add, if you need to know which page is actually a multiple of 50, use can always check with (pageNumber % 50 == 0)
– awsmsce
Nov 11 at 19:21
thanks @suvojit_007 works great
– Ken
Nov 11 at 19:21
@awsmsce Correct, but iterating only on multiple values of 50 is a better option than to check for each number using%
with an increment step of1
.
– vivek_23
Nov 11 at 19:28
1
:thumbs up: @vivek_23
– awsmsce
Nov 11 at 20:02
1
@Ken you should "Accept" this Answer since you commented it "works great" (and then it will get the green checkmark making it more clear that this Answer works). Glad you got your answer.
– cellepo
Nov 11 at 20:07
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252246%2fhow-to-for-loop-for-every-50th-number-start-to-end-point-in-php%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
use $p+=50
instead of $p++
for($p=$startpage;$p<=$endpage;$p+=50)
echo file_get_html("mysite.com/mypage.php?offset=$p"); // it will work like offset=0, offset=50, offset=100, offset=150, offset=200
All additionally just add, if you need to know which page is actually a multiple of 50, use can always check with (pageNumber % 50 == 0)
– awsmsce
Nov 11 at 19:21
thanks @suvojit_007 works great
– Ken
Nov 11 at 19:21
@awsmsce Correct, but iterating only on multiple values of 50 is a better option than to check for each number using%
with an increment step of1
.
– vivek_23
Nov 11 at 19:28
1
:thumbs up: @vivek_23
– awsmsce
Nov 11 at 20:02
1
@Ken you should "Accept" this Answer since you commented it "works great" (and then it will get the green checkmark making it more clear that this Answer works). Glad you got your answer.
– cellepo
Nov 11 at 20:07
add a comment |
up vote
2
down vote
accepted
use $p+=50
instead of $p++
for($p=$startpage;$p<=$endpage;$p+=50)
echo file_get_html("mysite.com/mypage.php?offset=$p"); // it will work like offset=0, offset=50, offset=100, offset=150, offset=200
All additionally just add, if you need to know which page is actually a multiple of 50, use can always check with (pageNumber % 50 == 0)
– awsmsce
Nov 11 at 19:21
thanks @suvojit_007 works great
– Ken
Nov 11 at 19:21
@awsmsce Correct, but iterating only on multiple values of 50 is a better option than to check for each number using%
with an increment step of1
.
– vivek_23
Nov 11 at 19:28
1
:thumbs up: @vivek_23
– awsmsce
Nov 11 at 20:02
1
@Ken you should "Accept" this Answer since you commented it "works great" (and then it will get the green checkmark making it more clear that this Answer works). Glad you got your answer.
– cellepo
Nov 11 at 20:07
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
use $p+=50
instead of $p++
for($p=$startpage;$p<=$endpage;$p+=50)
echo file_get_html("mysite.com/mypage.php?offset=$p"); // it will work like offset=0, offset=50, offset=100, offset=150, offset=200
use $p+=50
instead of $p++
for($p=$startpage;$p<=$endpage;$p+=50)
echo file_get_html("mysite.com/mypage.php?offset=$p"); // it will work like offset=0, offset=50, offset=100, offset=150, offset=200
answered Nov 11 at 19:15
suvojit_007
1,3151517
1,3151517
All additionally just add, if you need to know which page is actually a multiple of 50, use can always check with (pageNumber % 50 == 0)
– awsmsce
Nov 11 at 19:21
thanks @suvojit_007 works great
– Ken
Nov 11 at 19:21
@awsmsce Correct, but iterating only on multiple values of 50 is a better option than to check for each number using%
with an increment step of1
.
– vivek_23
Nov 11 at 19:28
1
:thumbs up: @vivek_23
– awsmsce
Nov 11 at 20:02
1
@Ken you should "Accept" this Answer since you commented it "works great" (and then it will get the green checkmark making it more clear that this Answer works). Glad you got your answer.
– cellepo
Nov 11 at 20:07
add a comment |
All additionally just add, if you need to know which page is actually a multiple of 50, use can always check with (pageNumber % 50 == 0)
– awsmsce
Nov 11 at 19:21
thanks @suvojit_007 works great
– Ken
Nov 11 at 19:21
@awsmsce Correct, but iterating only on multiple values of 50 is a better option than to check for each number using%
with an increment step of1
.
– vivek_23
Nov 11 at 19:28
1
:thumbs up: @vivek_23
– awsmsce
Nov 11 at 20:02
1
@Ken you should "Accept" this Answer since you commented it "works great" (and then it will get the green checkmark making it more clear that this Answer works). Glad you got your answer.
– cellepo
Nov 11 at 20:07
All additionally just add, if you need to know which page is actually a multiple of 50, use can always check with (pageNumber % 50 == 0)
– awsmsce
Nov 11 at 19:21
All additionally just add, if you need to know which page is actually a multiple of 50, use can always check with (pageNumber % 50 == 0)
– awsmsce
Nov 11 at 19:21
thanks @suvojit_007 works great
– Ken
Nov 11 at 19:21
thanks @suvojit_007 works great
– Ken
Nov 11 at 19:21
@awsmsce Correct, but iterating only on multiple values of 50 is a better option than to check for each number using
%
with an increment step of 1
.– vivek_23
Nov 11 at 19:28
@awsmsce Correct, but iterating only on multiple values of 50 is a better option than to check for each number using
%
with an increment step of 1
.– vivek_23
Nov 11 at 19:28
1
1
:thumbs up: @vivek_23
– awsmsce
Nov 11 at 20:02
:thumbs up: @vivek_23
– awsmsce
Nov 11 at 20:02
1
1
@Ken you should "Accept" this Answer since you commented it "works great" (and then it will get the green checkmark making it more clear that this Answer works). Glad you got your answer.
– cellepo
Nov 11 at 20:07
@Ken you should "Accept" this Answer since you commented it "works great" (and then it will get the green checkmark making it more clear that this Answer works). Glad you got your answer.
– cellepo
Nov 11 at 20:07
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252246%2fhow-to-for-loop-for-every-50th-number-start-to-end-point-in-php%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Not sure what the "it will work like" comment means.
– cellepo
Nov 11 at 20:01
The one Answer here (as of commenting now) is correct - but in general, even though this focuses on PHP, this question touches on the general idea of "loop guard" that is common to most languages in general. Learning more about loop guards in general sounds like it would be helpful for you.
– cellepo
Nov 11 at 20:06