troubleshooting Question

Paging with PHP

Avatar of narmi2
narmi2 asked on
4 Comments2 Solutions339 ViewsLast Modified:

I have the following php code which simply displays links on the page:

      if($_GET['id'] == "")
            echo getdata("");
            echo getdata("and link_group like '%".$_GET['id'].",%'");

      function getdata($querystring)
            $connection = mysql_connect('servername', 'password', '') or die (mysql_error());
            $db = mysql_select_db('database', $connection) or die (mysql_error());
            $query = "select * from link_info where archive = 0 and inactive = 0 and type = 'news' ".$querystring." order by display_date desc";
            $result = mysql_query($query) or die (mysql_error());
            global $the_data;

            $the_data = '';
            while ($row = mysql_fetch_array($result))
                  $new_date = date('F Y', strtotime($display_date));
                  $the_data = $the_data."<div class='newsdate'>$new_date</div>";
                  $the_data = $the_data."<div class='newssubject'><a href='links/news/$file_name' title='Download $description link'><img src='images/linkicon_small.gif' alt='link' width='17' height='17' /> $description</a></div>";
                  $the_data = $the_data."<div class='clear'></div>";
            return $the_data;

How do I create paging with this?  So it only displays 15 results at a time.  If they want to see the next 15, they have to click the page number at the bottom, i.e. Page 1,2,3,4.  The page number depends on how many links are returned,  so if <= 15 links are returned, it only displays page 1, if more > 15 and <= 30 it should display Page 1,2.  and so on.

Can this be done?
Enterprise Web Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros