SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pagination ala Sitepoint

    I look around various tutorials on the web and posts on this forum about pagination and the majority of them are based on, for example, displaying 100 rows from your database, where each row is a product and displaying a maximum of 10 results per page. As a result the script creates
    << PREV [1][2][3][4][5][6][7][8][9][10] NEXT >>
    at the base of the page.

    But what I'm trying to replicate is the same as the long articles on Sitepoint.com
    http://www.sitepoint.com/article/php...1-1-php-basics.
    In the sitepoint example I assume that the page numbers refers to 7 rows in a table, 1 page per row.

    Would it use the same kind of pagination code that the "displaying 10 'products' a page" tutorials do except I just display a maximum of 1 row per page?

  2. #2
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I could be wrong but I don't think the SitePoint articles are divided up into pages in the same way that a pagination script would divide say, a search results list into 20 items per page. Rather, it is based on a logical split of the subject matter. As such, article pages are probably divided merely to keep the pages from being too long.

    I'm sure you know this, but the number of pages your display would end up being is determined by the total number of rows divided by how many entries per page you want. You can take any existing script and specify those values and get the kind of display you want.

    I guess I'm a little confused as to what you're really trying to do and why there isn't an existing script you can use.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  3. #3
    SitePoint Zealot saurab's Avatar
    Join Date
    Sep 2004
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Googly
    I look around various tutorials on the web and posts on this forum about pagination and the majority of them are based on, for example, displaying 100 rows from your database, where each row is a product and displaying a maximum of 10 results per page. As a result the script creates
    << PREV [1][2][3][4][5][6][7][8][9][10] NEXT >>
    at the base of the page.

    But what I'm trying to replicate is the same as the long articles on Sitepoint.com
    http://www.sitepoint.com/article/php...1-1-php-basics.
    In the sitepoint example I assume that the page numbers refers to 7 rows in a table, 1 page per row.

    Would it use the same kind of pagination code that the "displaying 10 'products' a page" tutorials do except I just display a maximum of 1 row per page?
    If you're looking for a tutorial on how to develop scripts for displaying lengthy articles split across several pages, there is a nice tutorial on devarticles :
    http://www.devarticles.com/c/a/ASP/B...-With-ASP-PHP/

    --saurab
    Accepting Offers: NicheLabs.com - ExploringVOIP.com
    StableJob.com - AboutUniversities.com - Gemstone.co.in
    Assets.co.in - PropertyDealers.org - MortgageFirms.org
    eLearner.org - TravelResorts.info - TourstoAsia.com



  4. #4
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess I'm a little confused as to what you're really trying to do and why there isn't an existing script you can use.
    I suppose I'm slightly confused myself as to what the best solution is. In hindsight my need is slightly different to splitting a large article, but i suppose i could do it like that.

    What I have is a sports club website. It has a history section which consists of about 10 pages, each page a different era of the club. These ten pages are part of the complete history of the club as opposed to another history section of 3 pages which is 'An abridged Version of the Club's History'. It does look like this may fit into the tutorial that saurab suggested.

    Do you agree that this is the best way to do it? I mean if each page is in a separate row then I won't be losing much using the tutorial. I can still have certain titles, headings, pictures etc attached to the specific page if i choose to.

  5. #5
    SitePoint Zealot saurab's Avatar
    Join Date
    Sep 2004
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Googly
    I suppose I'm slightly confused myself as to what the best solution is. In hindsight my need is slightly different to splitting a large article, but i suppose i could do it like that.

    What I have is a sports club website. It has a history section which consists of about 10 pages, each page a different era of the club. These ten pages are part of the complete history of the club as opposed to another history section of 3 pages which is 'An abridged Version of the Club's History'. It does look like this may fit into the tutorial that saurab suggested.

    Do you agree that this is the best way to do it? I mean if each page is in a separate row then I won't be losing much using the tutorial. I can still have certain titles, headings, pictures etc attached to the specific page if i choose to.
    from what I understand, the following db schema should be suitable for your needs : (i've copied and pasted a part of the schema from one of my own projects)

    Code:
     
    #-------------------------------------------------------------------
    #
    # Table Structure for table document  
    #
    CREATE TABLE IF NOT EXISTS document (
      documentId int(11) UNSIGNED NOT NULL auto_increment,
      documentType enum('NEWS', 'ARTICLE') NOT NULL,
      authorId mediumint(8) UNSIGNED NOT NULL, 
      approverId mediumint(8) UNSIGNED NOT NULL,
      sectionId tinyint(3) UNSIGNED NOT NULL,
      documentTitle varchar(255) NOT NULL default '',
      documentAbstract text NOT NULL default '',
      numPages tinyint(3) NOT NULL default '1',
      publishDate datetime NOT NULL default '0000-00-00 00:00:00',
      rating tinyint(3) UNSIGNED,
      numberOfVotes decimal(5,2),
      modifiedDate datetime NOT NULL default '0000-00-00 00:00:00',
      modifiedBy mediumint(8) unsigned NOT NULL default '0',
      UNIQUE KEY documentTitle (documentTitle),
      PRIMARY KEY (documentId),
      KEY authorId (authorId),
      KEY sectionId (sectionId),
    )TYPE=MyISAM;
    
    #----------------------------------------------------------------------
    #
    # Table Structure for table document_pages  
    #
    CREATE TABLE IF NOT EXISTS document_pages (
      documentId int(11) UNSIGNED NOT NULL,
      pageNumber tinyint(3) UNSIGNED NOT NULL,
      documentTitle varchar(255) NOT NULL default '',
      pageTitle varchar(150) NOT NULL default '',
      pageBody text NOT NULL default '',
      pageDisplayUrl varchar(125) NOT NULL default '',
      pageCacheUrl varchar(125) NOT NULL default '',
      PRIMARY KEY (documentId, pageNumber)
    )TYPE=MyISAM;
    so, with this schema, you have a document (which can be an article, or which can be any other "set" of pages related to something... in your case club's history). and this document can have several pages with their own unique page title and body and url etc .....

    this is extensible too, for later on if you have another "related set of pages" to accomodate, you can do so with this schema.

    --saurab
    Accepting Offers: NicheLabs.com - ExploringVOIP.com
    StableJob.com - AboutUniversities.com - Gemstone.co.in
    Assets.co.in - PropertyDealers.org - MortgageFirms.org
    eLearner.org - TravelResorts.info - TourstoAsia.com



  6. #6
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Saurub. that will undoubtedly give me some ideas in the near future.
    After a short while away I am back to this and have used the devarticle tutorial to create some php code to create the pagination for my articles.

    You won't really need to closely analyse the code which i'm about to post, but I'll post it all just in case it helps. My problem is that I have the pagination page links created at the end of the article, however I also want the pagination links at the top of the page under the headline echo '<h1>'.$row[headline].'</h1>';

    I'm not exactly sure how to do this though. I have been trying things such as repeating the while loop, but I can't create the 2 groups of page links (one at the top of the page and one at the bottom). Is something like a defined function needed? Please help I'm a bit clueless.

    PHP Code:
    <?php

    include_once('../../Connections/db_fns.php');
    include(
    '../includes/header2.php');   

    $article_id = @$_GET["article_id"];
    $page_id = @$_GET["page_id"];

    if(!
    is_numeric($article_id))
    {
    die(
    "Invalid article ID");
    }

    $conn db_connect();

    if(
    $page_id == "")
    {
      
    $sql='select page_id from historypages where article_id=' $article_id ' limit 1';
      
    $result mysql_query($sql$conn) or die ('Failed to execute ' $sql ' due to ' mysql_error());

    //insert code like csccpage
    $row mysql_fetch_array($result);
    $page_id $row["page_id"];
    }
     
    $sql='select pagecontent, story_text, pagetitle, headline, subheading from stories inner join historypages on stories.article_id = historypages.article_id where stories.article_id = ' $article_id ' and historypages.page_id = ' $page_id;  
     
    $result mysql_query($sql$conn) or die ('Failed to execute ' $sql ' due to ' mysql_error());

    if(
    mysql_num_rows($result) == 0)
    {
    die(
    "Article not found");
    }

    $row mysql_fetch_array($result);
        echo 
    '<h1>'.$row[headline].'</h1>';
      
    ?><i><h2><?php 
    if ($page_id == 1) {
        echo 
    $row[subheading];
    } else {
        echo 
    $row[pagetitle];
    }
    ?></h2></i><p><?php
    if ($page_id == 1) {
        echo 
    $row[story_text];
    } else
        echo 
    $row[pagecontent];
    ?></p></font><?php 
    //Display the pages in this article
    $sql 'select * from historypages where article_id = ' $article_id;
      
    $result mysql_query($sql$conn) or die ('Failed to execute ' $sql ' due to ' mysql_error());

    // code for page numbers
        
    echo "&raquo; Page ";
    while(
    $row mysql_fetch_array($result))
    {
    if(
    $page_id == $row["page_id"]) {
        echo 
    " <b>" $row["page_id"] . "</b>";
    }
    elseif (
    $row["page_id"] == 1){
        echo 
    " <a href='displayarticle.php?article_id=" $article_id "'>" $row["page_id"] . "</a>";}
    else
        echo 
    " <a href='displayarticle.php?article_id=" $article_id "&page_id=" $row["page_id"] . "'>" $row["page_id"] . "</a>";
    }
    require(
    '../includes/historyfooter.inc');
    ?>

  7. #7
    SitePoint Zealot saurab's Avatar
    Join Date
    Sep 2004
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Googly
    Thanks Saurub. that will undoubtedly give me some ideas in the near future.
    After a short while away I am back to this and have used the devarticle tutorial to create some php code to create the pagination for my articles.

    You won't really need to closely analyse the code which i'm about to post, but I'll post it all just in case it helps. My problem is that I have the pagination page links created at the end of the article, however I also want the pagination links at the top of the page under the headline echo '<h1>'.$row[headline].'</h1>';
    Hi,
    I see from the code you've posted that you're running a query to find out the page ids for the article requested. What you can do is to take that query and put it inside a function, and then call that function once at the top of the page. Make it so that this function receives the article id , runs a query on the db , which if the article exists would return an array of page ids corresponding to the article, else it would return false. If the function returns false you know the article is invalid.
    yeah one more thing... when the function (called at the top) returns an array assign that array to some array variable... and use it in two places once at the top and once at the bottom. so the main thing is to call this function before doing anything else like displaying an article page .......and since you are calling this function before displaying the article , you will also know through this function whether there was indeed a valid article with this id in the database.

    --saurab
    Accepting Offers: NicheLabs.com - ExploringVOIP.com
    StableJob.com - AboutUniversities.com - Gemstone.co.in
    Assets.co.in - PropertyDealers.org - MortgageFirms.org
    eLearner.org - TravelResorts.info - TourstoAsia.com



  8. #8
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by saurab
    I see from the code you've posted that you're running a query to find out the page ids for the article requested. What you can do is to take that query and put it inside a function, and then call that function once at the top of the page. Make it so that this function receives the article id , runs a query on the db , which if the article exists would return an array of page ids corresponding to the article, else it would return false. If the function returns false you know the article is invalid.
    Is this something like what you mean? I'm not too good at this, there's something wrong.
    PHP Code:
    function numofpages ($article_id$page_id$conn) {
    {
    $sql='select page_id from historypages where article_id=' $article_id ' limit 1';
      
    $result mysql_query($sql$conn) or die ('Failed to execute ' $sql ' due to ' mysql_error());
    $row mysql_fetch_array($result);
    $page_id $row["page_id"];

    }
    }

    numofpages ($article_id$page_id$conn);
    if (!isset(
    $page_id)) {echo 'Invalid article';} 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •