473,396 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

pagination

I tried to do pagination of an article with an arbitrary 2500 characters per
page but if
the cutoff point is not the end of a paragraph (<br><br>), it would be moved
there instead. I am using php5. Here is the skeleton of my code:

$length = strlen($article);
$charsPerPage = 2500;
$numberOfPages = ceil($length/$charsPerPage);
$start = 0;

for($counter=1;counter<$numberOfPages + 1;$counter++) {
$cutOffPoint= strripos(substr($all, $start, $charsPerPage),
'<br><br>');
$pageContent = substr($article, $start, $cutOffPoint-$start);
$start = $cutOffPoint;
echo "page".counter." = ".$pageContent;
}

However, it only works for the first loop for some reason. In the
subsequent loop the $cutOffPoint is located even before the $start (visible
when I
print them out for testing purpose). Could someone show me what I am
missing?
Thanks.


Jun 2 '07 #1
2 1308
Peter Parker wrote:
$numberOfPages = ceil($length/$charsPerPage);
This is plain false...
$cutOffPoint= strripos(substr($all, $start, $charsPerPage),
'<br><br>');
$pageContent = substr($article, $start, $cutOffPoint-$start);
$cutOffPoint is relative to "substr($all, $start, $charsPerPage)", not
relative to $article. By the way, why do you have $all and $article??
Besides that, your algorithm doesn't take into account extreme cases: what
if I have no "<br>" at all in my article? What if my article is nothing but
a lot of "<br>"s?

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

"Only sick music makes money today."
-- Friedrich Nietzsche [1844 - 1900]
Jun 2 '07 #2
Sorry, it should have been '$article' instead of '$all'. I renamed and
missed that one when I posted onto newsgroup. The article format is created
by me so I make sure the format holds. I did print it out to verify. It
contains only text strings in English language with single newline as <br>
and double newlines for new paragraph as <br><br>. Thanks.
"Iván Sánchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
wrote in message news:f3**********@hercules.cohp1...
Peter Parker wrote:
>$numberOfPages = ceil($length/$charsPerPage);

This is plain false...
> $cutOffPoint= strripos(substr($all, $start, $charsPerPage),
'<br><br>');
$pageContent = substr($article, $start, $cutOffPoint-$start);

$cutOffPoint is relative to "substr($all, $start, $charsPerPage)", not
relative to $article. By the way, why do you have $all and $article??
Besides that, your algorithm doesn't take into account extreme cases: what
if I have no "<br>" at all in my article? What if my article is nothing
but
a lot of "<br>"s?

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

"Only sick music makes money today."
-- Friedrich Nietzsche [1844 - 1900]

Jun 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Sharif T. Karim | last post by:
Anyone know of a up-to-date tutorial for pagination where I can have it like: Prev 1 2 3 4 Next Thanks. -- Sharif T. Karim ....you don't know wrath yet...
1
by: Faree | last post by:
I am workign on a news portal which needs paginaiton as usual.but all the code i got depends on the number of records that will come from database :( .it is working well too. But i need...
1
by: Kruq | last post by:
Is it possible to use pagination with DataList? Can't find it.. :( Kruq
2
by: Chris H | last post by:
I am having a problem with pagination, basically the problem is happening in the "PREV / NUMBERS / NEXT" links, it appears as if the reason is becasue the increment and decrement operators aren't...
11
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. ...
1
by: dhanu | last post by:
How to manage pagination in AJAX? My requirement is similar to GMails inbox feature. Whenever a new mail comes in,the newly arrived mail is at the start of my inbox and last row in that page...
1
by: shalini jain | last post by:
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code. Below is the code that...
16
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) ...
4
by: ArizonaJohn | last post by:
Hello, The code below works great. The user enters a name into an HTML form, the code looks up a table with that name, and then that table is displayed. I am trying to use pagination with it,...
2
by: kkshansid | last post by:
this is my search page on which i am getting two parameters from previous page but the problem is that as soon as i click any other next pages my sql query fails as it doesnt get these two parameters...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.