PHP Installation
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Installation

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
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  
Old March 27th, 2004, 08:02 AM
BabyPinkHeart BabyPinkHeart is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Sydney, Australia
Posts: 6 BabyPinkHeart User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to BabyPinkHeart
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!

Reply With Quote
  #2  
Old March 30th, 2004, 02:05 AM
BabyPinkHeart BabyPinkHeart is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Sydney, Australia
Posts: 6 BabyPinkHeart User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to BabyPinkHeart
RE: PHP Loop Calculations

Can anyone help, please?

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Installation > PHP Loop Calculations


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway