|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
PHP Loop Calculations
Hi!
I don't really know PHP. I'm using a code that calls text file entries and prints it out to the screen. I tried my hands on it without success. The first page prints out really good, exactly what I want - the latest entry at the top and the number starts at the total number of entries. But when I go to the next page (shows the next 10 recent entries), it adds up the total number of entries then the calculation starts there. For example, if there are a total number of 50 entries, the output will be for the first page is: 50 - Tyrese 49 - Beyonce 48 - Kelly 47 - Michelle 46 - Aaliyah 45 - Usher 44 - Tupac 43 - Brian McKnight 42 - Jessica Alba 41 - Johnny Depp Then for the second page: 60 - Twista 59 - Tamia 58 - Fabolous 57 - Me 56 - Lee 55 - Josh 54 - Dat 53 - Lis 52 - Ann 51 - Fayzie Instead of: (second page) 40 - Twista 39 - Tamia 38 - Fabolous 37 - Me 36 - Lee 35 - Josh 34 - Dat 33 - Lis 32 - Ann 31 - Fayzie This is the code that I have: <?php $fileName = file ("guestbook.txt"); $rows = count ($fileName); $idtotal = count ($fileName); $u_id = 1; if ($rows > 10) { if (!isset ($row) ) { $row = 0; } print ("<table class="guestbookLinks" width="100%"><tr><td>"); if ($row > 0) { echo "<p class="nextPage"><< <a href="readbook.php?row=" . ($row - 10) . "">Previous 10 </a></p>"; } print ("</td><td>"); if ( ($rows - $row) > 10) { echo "<p class="previousPage"><a href="readbook.php?row=" . ($row + 10) . "">Next 10 </a> >></p>"; } print ("</td></tr></table>"); for ($i = $row; $i < ($row + 10); $i++) { print ("<p>"); echo $row + $idtotal + $u_id . " " . $fileName [$i] . "<br>"; $u_id--; print ("<img src="../../images/divide.gif" width="36" height="28" alt="New"></p>"); } print ("<table class="guestbookLinks" width="100%"><tr><td>"); if ($row > 0) { echo "<p class="nextPage"><< <a href="readbook.php?row=" . ($row - 10) . "">Previous 10 </a></p>"; } print ("</td><td>"); if ( ($rows - $row) > 10) { echo "<p class="previousPage"><a href="readbook.php?row=" . ($row + 10) . "">Next 10 </a> >></p>"; } print ("</td></tr></table>"); } else { for ($i=0; $i < $rows; $i++) { echo $fileName [$i]; } } ?> Thank you, any help is appreciated. Thanx! |
|
#2
|
|||
|
|||
|
RE: PHP Loop Calculations
Can anyone help, please?
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Installation > PHP Loop Calculations |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
![]() |
|