Pagination where to start?

Hi there…

here is my test/demo site
link demo site

herecontent of the page comes from the database field. from the id=2

but problem is if the content is large then the page will be too long. like if the content have more than 50 paragraphs.

so ineedpagination for this conetent.

but i dont know how to start. any tutorial or help for this?

here is the code for the page is

<?php mysql_connect('localhost', 'ash', 'lash') or die('Connection Failed');
mysql_select_db('lash') or die('Database not found');
$id = (int) $_GET['id'];  
$result = mysql_query("SELECT title, dtl, meta_description, meta_keywords FROM page WHERE id=$id");
if (!mysql_num_rows($result)) {     header('Location: 404.php', true, 404);     die();}$row = mysql_fetch_array($result);$title = stripslashes($row['title']);$dtl = stripslashes($row['dtl']);$meta_desc = stripslashes($row['meta_description']);$meta_keys = stripslashes($row['meta_keywords']);?><html><head><meta name="description" content="<?php echo $meta_description; ?>" /><meta name="keywords" content="<?php echo $meta_keywords; ?>" /><title> - <?php echo $title; ?></title></head><body><h1><?php echo $title; ?></h1><?php echo $dtl; ?></body></html>

Where to start: Come up with the logic plan.

Here’s mine in broad strokes:

  1. Decide your ‘limit’.
  2. Check for size > limit.
    3a. If true, paginate based on the breaks, and display relevant section.
    3b. If false, display whole thing.

gr8. thanks for the useful reply

can you please suggest any tutorial where from i can uderstand the process or steps that you mentioned above? iam newbie in php

PHP Freaks - PHP Help Tutorial: PHP Basic Pagination

Essentially, you are going to have PHP exploit Mysql’s LIMIT clause so may need more work if you are using another rdms.

can you explain more please .what is rdms?

Apparently Google is broken for you :wink: … [google]rdbms[/google]

[google]PHP Pagination[/google]

i googled. but everywhere i found the pagination for rows.


// Create MySQL Query String
$strqry = “SELECT id from MyTable”;
$query = mysql_query($strqry) or die("MySQL Error: <br /> {$strqry} <br />", mysql_error());
// Get number of rows returned
$TOTALROWS = mysql_num_rows();
// Figure out how many pages there should be based on your $LIMIT
$NumOfPages = $TOTALROWS / $LIMIT;
// This is for your MySQL Query to limit the entries per page
$LimitValue = $page * $LIMIT – ($LIMIT);

but in my part it pull data from a id by using url variable
link is here
it pull data from row/id 2

i am not understanding how can i manage it.

p.s: sorry if iam a stupid but iam very eager to know

From what I understand you as saying is you want to paginate across text data that you’re retrieving. So I’m going to ask you to figure out Step #1 from my plan above. How much data do you want to show?

my datas are full of paragraphs,images and tables…

i want to show atleast 7 paragraphs 2/3 images and 2/3 tables on page.

can anybody help?

by googling All the tutorials I’ve found on pagination always refer to paginating multiple rows out of a database. Like displaying 5 rows on each page. But I’m trying to paginate an article that is being stored in one row of the table.

my table name is “page”

in the table “page” there is 4 rows

id | title | meta_description| meta_keywords |article

1 | title1 | meta 1| meta kewords |articles text1 bla blabla
2 | title2 | meta 2| meta kewords |articles text2 bla blabla
3 | title3 | meta 3| meta kewords |articles text3 bla blabla
4 | title4 | meta 4| meta kewords |articles text4 bla blabla

so in id=1 in the article text there is a article which almost 10 page size. so i need pagination for this article

But how?

We do tend to do this thing called sleeping from time to time :stuck_out_tongue:

So you’ve set a limit of 7 paragraphs. (The images/tables follow the same theory, so we’ll stick with the paragraphs for now)

Take a look at [FPHP]explode[/FPHP], and [FPHP]count[/FPHP], and figure out how to determine if the data is larger than your limit.

Let me get this right.

Your table is a blob of text.

That text contains the markup for 1 article and that article could contain html tables and html for images.

You are not exactly sure what makes up a “page”, but by your own estimation there could be up to 10 of them.

I guess that in a worst case scenario 1 table could make up one page, or could even span more than a single page.

Am I about right?

$page_limit = 300;
$page = explode(" ", $article, $page_limit );
$page_count = count($page);
$page_count = $page_count - 1;
foreach ( $page as $key => $value ):

yes absolutely. sorry for ignorance my bad english and if iam wrong :frowning:

Sounds like you need to rethink the way your storing the data. Tossing everything in a single column is not going to make anything easy. That said the only way you could really achieve what you want with your current schema is to use some regex magic but that is just horrible way to do in the first place. Rethink the schema properly isolating pieces of info into separate tables and this will be much simpler and reliable.

You need a concrete definition of a page. Only then can it be translated to programmatic logic.

Edit: One way to achieve your goals with ease would be to have people set a marker where a page ends and another begins. Than you would actually have a concrete definition.

That is what I imagined, insert, say, a <hr /> where you want the “page” to naturally break, that way you also have the option of showing the whole article.

Ideally you would insert that <hr /> as the article is written, but to be honest if you have this kind of control you may as well create the pages as separate entries in the database.

one of my friend suggest his one

[I][B]Any place you want a page you would just put (in your article), “{page}” (or whatever you want to use as the page delimiter).

Then when you display the page, you will explode the article by the delimiter (“{page}”). This will create an array of pages for the number of delimiters you used.

Then, the method of generating the page links is the same as other pagination tutorial[/B][/I]

But iam not understanding this how to do…