Reputation: 303
How do i echo a value for each certain loop (4th) if my starting count number is 0? For example, the count is 0,1,2,3,4,6,7,8,9,10,11,12,13
I need it to echo/print on the following numbers: 3,8,12,16
Here's my loop codes:
$Num_Rows = mssql_num_rows($query);
$Per_Page = 16; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"]){
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page){
$Num_Pages =1;
} else if(($Num_Rows % $Per_Page)==0) {
$Num_Pages =($Num_Rows/$Per_Page) ;
} else {
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$Page_End = $Per_Page * $Page;
IF ($Page_End > $Num_Rows) {
$Page_End = $Num_Rows;
}
$VALUE = 'last';
echo '<ul>';
for($i=$Page_Start;$i<$Page_End;$i++) {
<li class="<?php if ($pages % 4 == 0) { echo $VALUE; }?>">Test</li>
}
echo '</ul>';
It kind of works but unfortunately, it starts printing the $VALUE on #0
So it prints on the following count/numbers: 0,4,8,12
Instead of the correct ones: 3,8,12,16
Upvotes: 0
Views: 129
Reputation: 155
Try this:
$Num_Rows = mssql_num_rows($query);
$Per_Page = 16; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"]){
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page){
$Num_Pages =1;
} else if(($Num_Rows % $Per_Page)==0) {
$Num_Pages =($Num_Rows/$Per_Page) ;
} else {
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
$Page_End = $Per_Page * $Page;
IF ($Page_End > $Num_Rows) {
$Page_End = $Num_Rows;
}
$VALUE = 'last';
echo '<ul>';
for($i=$Page_Start;$i<$Page_End;$i++) {
<li class="<?php if (($pages+1) % 4 == 0) { echo $VALUE; }?>">Test</li>
}
echo '</ul>';
Upvotes: 2