<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: MySQL + PHP Simple Pagination</title>
	<atom:link href="http://www.pk-tuts.co.uk/php/php-tutorials/mysql-php-simple-pagination/feed" rel="self" type="application/rss+xml" />
	<link>http://www.pk-tuts.co.uk/php/php-tutorials/mysql-php-simple-pagination?utm_source=subscriber&amp;utm_medium=rss&amp;utm_campaign=rss</link>
	<description>Written By Peter Kelly</description>
	<lastBuildDate>Wed, 10 Mar 2010 22:41:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Rob Adshead</title>
		<link>http://www.pk-tuts.co.uk/php/php-tutorials/mysql-php-simple-pagination/comment-page-1#comment-21</link>
		<dc:creator>Rob Adshead</dc:creator>
		<pubDate>Wed, 10 Mar 2010 22:41:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.pk-tuts.co.uk/?p=215#comment-21</guid>
		<description>I was working on this script for my own website and I made the pages more advanced

&lt;pre lang=&quot;PHP&quot;&gt;&lt; ?php

    $offset = mysql_escape_string(strip_tags($_GET[&#039;offset&#039;]));
    $limit = mysql_escape_string(strip_tags($_GET[&#039;limit&#039;]));
     
    if(empty($limit)){
        $limit = &quot;25&quot;;
    }
    if(empty($offset) &#124;&#124; $offset &lt; 0){
        $offset = &quot;0&quot;;
    }

     
    $result = mysql_query(&quot;SELECT * FROM `table` LIMIT &quot; . $limit . &quot; OFFSET &quot; . $offset);
    while($row = mysql_fetch_object($result))
    {
		?&gt;
        
        	options
         
    	&lt; ?
    }

    $previous = $offset - &quot;1&quot;; 
    $next = $offset + &quot;1&quot;;
     
    if($previous &lt; 0){
        $previous = &quot;0&quot;;
    }
			
			$sql = mysql_query(&quot;SELECT * FROM licenses&quot;);
			$sql1 = mysql_query(&quot;SELECT table FROM licenses ORDER BY id DESC LIMIT 1&quot;);
			$row1 = mysql_fetch_object($sql1);
			$rows = mysql_num_rows($sql); 
		
			$offset1 = $offset + $limit;
					
			if($rows &gt; $limit &amp;&amp; $offset == &quot;0&quot;){ // if its the first page it only gives next if more pages are avaiable
				
	?&gt;

   					&lt;a href=&quot;?offset=&lt;?= $next ? rel=&quot;nofollow&quot;&gt;&amp;limit=&lt; ?= $limit ?&gt;&quot; class=&quot;link&quot;&gt;Next&lt;/a&gt;

   
	&lt; ?
			}elseif($row1-&gt;licenseId &lt; = $offset1 &amp;&amp; $offset != &quot;0&quot;){ // if its the last page it will only give previoous
			 
	?&gt;

    				 &lt;a href=&quot;?offset=&lt;?= $previous ? rel=&quot;nofollow&quot;&gt;&amp;limit=&lt; ?= $limit ?&gt;&quot; class=&quot;link&quot;&gt;Previous&lt;/a&gt;
     &lt; ?
			}elseif($rows &gt; $limit &amp;&amp; $offset != &quot;0&quot;){ // if its in the middle and theres pages to the left and right of the current page it gives the option for both
    ?&gt; 
           			 &lt;a href=&quot;?offset=&lt;?= $previous ? rel=&quot;nofollow&quot;&gt;&amp;limit=&lt; ?= $limit ?&gt;&quot; class=&quot;link&quot;&gt;Previous&lt;/a&gt; &#124;  &lt;a href=&quot;licenses.php?offset=&lt;?= $next ? rel=&quot;nofollow&quot;&gt;&amp;limit=&lt; ?= $limit ?&gt;&quot; class=&quot;link&quot;&gt;Next&lt;/a&gt;

	&lt; ?
			}else{ // if theres no pages appart from the 1 it doesn&#039;t give any options
	?&gt;
    &lt; ?
			}
			?&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I was working on this script for my own website and I made the pages more advanced</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt; ?php
&nbsp;
    $offset = mysql_escape_string(strip_tags($_GET['offset']));
    $limit = mysql_escape_string(strip_tags($_GET['limit']));
&nbsp;
    if(empty($limit)){
        $limit = &quot;25&quot;;
    }
    if(empty($offset) || $offset &lt; 0){
        $offset = &quot;0&quot;;
    }
&nbsp;
&nbsp;
    $result = mysql_query(&quot;SELECT * FROM `table` LIMIT &quot; . $limit . &quot; OFFSET &quot; . $offset);
    while($row = mysql_fetch_object($result))
    {
		?&gt;
&nbsp;
        	options
&nbsp;
    	&lt; ?
    }
&nbsp;
    $previous = $offset - &quot;1&quot;; 
    $next = $offset + &quot;1&quot;;
&nbsp;
    if($previous &lt; 0){
        $previous = &quot;0&quot;;
    }
&nbsp;
			$sql = mysql_query(&quot;SELECT * FROM licenses&quot;);
			$sql1 = mysql_query(&quot;SELECT table FROM licenses ORDER BY id DESC LIMIT 1&quot;);
			$row1 = mysql_fetch_object($sql1);
			$rows = mysql_num_rows($sql); 
&nbsp;
			$offset1 = $offset + $limit;
&nbsp;
			if($rows &gt; $limit &amp;&amp; $offset == &quot;0&quot;){ // if its the first page it only gives next if more pages are avaiable
&nbsp;
	?&gt;
&nbsp;
   					&lt;a href=&quot;?offset=<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$next</span> ? rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nofollow&quot;</span><span style="color: #339933;">&gt;&amp;</span>limit<span style="color: #339933;">=&lt;</span> ?<span style="color: #339933;">=</span> <span style="color: #000088;">$limit</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;link&quot;&gt;Next&lt;/a&gt;
&nbsp;
&nbsp;
	&lt; ?
			}elseif($row1-&gt;licenseId &lt; = $offset1 &amp;&amp; $offset != &quot;0&quot;){ // if its the last page it will only give previoous
&nbsp;
	?&gt;
&nbsp;
    				 &lt;a href=&quot;?offset=<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$previous</span> ? rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nofollow&quot;</span><span style="color: #339933;">&gt;&amp;</span>limit<span style="color: #339933;">=&lt;</span> ?<span style="color: #339933;">=</span> <span style="color: #000088;">$limit</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;link&quot;&gt;Previous&lt;/a&gt;
     &lt; ?
			}elseif($rows &gt; $limit &amp;&amp; $offset != &quot;0&quot;){ // if its in the middle and theres pages to the left and right of the current page it gives the option for both
    ?&gt; 
           			 &lt;a href=&quot;?offset=<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$previous</span> ? rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nofollow&quot;</span><span style="color: #339933;">&gt;&amp;</span>limit<span style="color: #339933;">=&lt;</span> ?<span style="color: #339933;">=</span> <span style="color: #000088;">$limit</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;link&quot;&gt;Previous&lt;/a&gt; |  &lt;a href=&quot;licenses.php?offset=<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$next</span> ? rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nofollow&quot;</span><span style="color: #339933;">&gt;&amp;</span>limit<span style="color: #339933;">=&lt;</span> ?<span style="color: #339933;">=</span> <span style="color: #000088;">$limit</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;link&quot;&gt;Next&lt;/a&gt;
&nbsp;
	&lt; ?
			}else{ // if theres no pages appart from the 1 it doesn't give any options
	?&gt;
    &lt; ?
			}
			?&gt;</pre></div></div>

]]></content:encoded>
	</item>
</channel>
</rss>
