Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Pagination

  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Pagination

    I have gotten my pagination working but can someone offer a suggestion how I can modify my code so that only the news entry area is affected? I don't want the main section to keep refreshing if the user has gone to other pages. Thanks for your time.

    Can be seen in action here in studio news area:http://www.rscottsculpture.com/index.php

    And the code for the news.inc where paging is going on:

    PHP Code:
    <?php 
    //make connection to database
    $con mysql_connect("localhost""thameu_visitor""visitor159") or die('Sorry, could not connect to database server');
    mysql_select_db("thameu_sculpture"$con) or die('Sorry, could not connect to database');

    $query "SELECT count(title) from news";
    $result mysql_query($query);
    $row=mysql_fetch_array($result);

    //if there are no articles say so
    if ($row[0] == 0)

    {
       echo 
    "No news posted yet.&nbsp;&nbsp;\n";
       
    //but if there are, get total records   
    } else

    {
       
    $totrecords $row[0];

    //set the page as 1
       
    if (!isset($_GET['page']))
          
    $thispage 1;
       else
          
    $thispage $_GET['page'];

    //how many articles to post per page   
       
    $recordsperpage 3;
       
    $offset = ($thispage 1) * $recordsperpage;
       
    $totpages ceil($totrecords $recordsperpage);

    $query "SELECT title,date,article from news order by date desc limit $offset,$recordsperpage";

       
    $result mysql_query($query) or die('Could not retrieve any news: ' mysql_error());


       while(
    $row mysql_fetch_array($resultMYSQL_ASSOC))

    //display the articles 
       
    {
        
    $date $row['date'];
        
    $title $row['title'];
        
    $article $row['article'];
        
        echo
    "<div style=\"width:95%;-webkit-border-radius: 20px;-moz-border-radius:         20px;border-radius: 20px;border:2px solid '#'802828;background:rgba(74,120,58,0.5);text-align:center;padding-left:4px;padding-right:4px;\">";
        echo 
    "<br>$date - $title<p>$article<br><br>";
        echo
    "</div>";
    }

       if (
    $thispage 1)

       {
          
    $page $thispage 1;
          
    $prevpage "<a href=\"index.php?newscontent=news.inc&page=$page\">Previous</a>";

       } else
       {
          
    $prevpage "";
       }
      
    $bar '';

       if (
    $totpages 1)

       { 

          for(
    $page 1$page <= $totpages$page++)

          {

             if (
    $page == $thispage)      
             {
                
    $bar .= " $page ";
             } else
             {
                
    $bar .= " <a href=\"index.php?newscontent=news.inc&page=$page\">$page</a> ";
             }
          }
       }

       if (
    $thispage $totpages)
       {
          
    $page $thispage 1;
          
    $nextpage " <a href=\"index.php?newscontent=news.inc&page=$page\">Next</a>";
       } else
       {
          
    $nextpage "";
       }
       echo 
    "Go to: " $prevpage $bar $nextpage;
    }
    ?>
    </div>
    Last edited by rscott; 06-18-2012 at 06:20 PM. Reason: formatting

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,045
    Thanks
    10
    Thanked 93 Times in 91 Posts
    an iframe or preferably AJAX so your 1,2, links etc would call a javascript method that rewrites your 'Studio News' content, its really a client side issue , I can move this post to javascript if you want.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New to the CF scene
    Join Date
    May 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you for your reply, go ahead and move it I'll give the javascript forum a shot.


  •  

    Tags for this Thread

    Posting Permissions

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