<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Pagination of Data using PHP-MySQL</title>
	<atom:link href="http://usefulscripts.wordpress.com/2007/10/26/pagination-using-php-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://usefulscripts.wordpress.com/2007/10/26/pagination-using-php-mysql/</link>
	<description>the scripts which are found rarely on the internet but needed often</description>
	<lastBuildDate>Mon, 27 Apr 2009 09:43:35 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: bovaum</title>
		<link>http://usefulscripts.wordpress.com/2007/10/26/pagination-using-php-mysql/#comment-37</link>
		<dc:creator>bovaum</dc:creator>
		<pubDate>Tue, 15 Apr 2008 17:08:55 +0000</pubDate>
		<guid isPermaLink="false">http://usefulscripts.wordpress.com/2007/10/26/pagination-using-php-mysql/#comment-37</guid>
		<description>thank you for the script,

I had to clean up the code a bit to make it work,

much happier when it looks like:

&lt;code&gt;

&lt;?php

$per_page = 10;

//REMEMBER TO CONNECT TO DATABASE!

$link=mysql_connect(&#039;localhost&#039;,&#039;USERNAME&#039;,&#039;PASSWORD&#039;);
mysql_select_db(&#039;DATABASE&#039;);

//**EDIT TO YOUR TABLE NAME, ECT.

$t = mysql_query(&#039;SELECT * FROM `users`&#039;); 
if(!$t) die(mysql_error());
   
$a= mysql_fetch_object($t);
$total_items= mysql_num_rows($t);

echo &#039;Total&#039;.$total_items;

$limit= $_GET[&#039;limit&#039;];
$page= $_GET[&#039;page&#039;];

//set default if: $limit is empty, non numerical, less than 10, greater than 50
if((!$limit)  &#124;&#124; (is_numeric($limit) == false) &#124;&#124; ($limit &lt; $per_page) ) {
     $limit = $per_page; //default
}
//set default if: $page is empty, non numerical, less than zero, greater than total available
if((!$page) &#124;&#124; (is_numeric($page) == false) &#124;&#124; ($page  $total_items)) {
      $page = 1; //default
}

//calcuate total pages
$total_pages = ceil($total_items / $limit);
$set_limit = ($page * $limit) - $limit;

echo &#039;&#039; . $set_limit . &#039;&#039;;

//query: **EDIT TO YOUR TABLE NAME, ECT.

$q = mysql_query(&quot;SELECT * FROM `users` LIMIT $set_limit, $limit&quot;);
if(!$q) die(mysql_error());
if(mysql_num_rows($q) == 0) die(&#039;No matches met your criteria.&#039;);

//Results per page: **EDIT LINK PATH**
 echo(&#039;
 &lt;a href=&quot;http://localhost/Code-Test/pagination/pagination.php?limit=10&amp;page=1&quot; rel=&quot;nofollow&quot;&gt;10&lt;/a&gt; &#124;
 &lt;a href=&quot;http://localhost/Code-Test/pagination/pagination.php?limit=25&amp;page=1&quot; rel=&quot;nofollow&quot;&gt;25&lt;/a&gt; &#124;
 &lt;a href=&quot;http://localhost/Code-Test/pagination/pagination.php?limit=50&amp;page=1&quot; rel=&quot;nofollow&quot;&gt;50&lt;/a&gt;
 &#039;);

//show data matching query:
while($code = mysql_fetch_object($q)) {
  //print your data here. 
echo(&#039;————————————–&#039;);
echo(&#039;Name: &#039;.$code-&gt;username.&#039;&#039;); 
echo(&#039;Math Marks: &#039;.$code-&gt;email.&#039;&#039;);
echo(&#039;Physics Marks: &#039;.$code-&gt;usertype.&#039;&#039;);
echo(&#039;————————————–&#039;);
}

//prev. page: **EDIT LINK PATH**

$prev_page = $page - 1;

if($prev_page &gt;= 1) {
  echo(&#039;&lt;b&gt;&lt;&lt;&lt;/b&gt; &lt;a href=&quot;http://localhost/Code-Test/pagination/pagination.php?limit=$limit&amp;page=$prev_page&quot; rel=&quot;nofollow&quot;&gt;&lt;b&gt;Prev.&lt;/b&gt;&lt;/a&gt;&#039;);
}

//Display middle pages: **EDIT LINK PATH**

for($a = 1; $a &lt;= $total_pages; $a++)
{
   if($a == $page) {
      echo(&quot;&lt;b&gt; $a&lt;/b&gt; &#124; &quot;); //no link
     } else {
  echo(&quot;  &lt;a href=&quot;http://localhost/Code-Test/pagination/pagination.php?limit=$limit&amp;page=$a&quot; rel=&quot;nofollow&quot;&gt; $a &lt;/a&gt; &#124; &quot;);
     }
}

//next page: **EDIT THIS LINK PATH**

$next_page = $page + 1;
if($next_page &lt;= $total_pages) {
   echo(&quot;&lt;a href=&quot;http://localhost/Code-Test/pagination/pagination.php?limit=$limit&amp;page=$next_page&quot; rel=&quot;nofollow&quot;&gt;&lt;b&gt;Next&lt;/b&gt;&lt;/a&gt; &gt; &gt;&quot;);
}

//all done
?&gt;
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>thank you for the script,</p>
<p>I had to clean up the code a bit to make it work,</p>
<p>much happier when it looks like:</p>
<p><code></p>
<p>&lt;?php</p>
<p>$per_page = 10;</p>
<p>//REMEMBER TO CONNECT TO DATABASE!</p>
<p>$link=mysql_connect('localhost','USERNAME','PASSWORD');<br />
mysql_select_db('DATABASE');</p>
<p>//**EDIT TO YOUR TABLE NAME, ECT.</p>
<p>$t = mysql_query('SELECT * FROM `users`');<br />
if(!$t) die(mysql_error());</p>
<p>$a= mysql_fetch_object($t);<br />
$total_items= mysql_num_rows($t);</p>
<p>echo 'Total'.$total_items;</p>
<p>$limit= $_GET['limit'];<br />
$page= $_GET['page'];</p>
<p>//set default if: $limit is empty, non numerical, less than 10, greater than 50<br />
if((!$limit)  || (is_numeric($limit) == false) || ($limit &lt; $per_page) ) {<br />
     $limit = $per_page; //default<br />
}<br />
//set default if: $page is empty, non numerical, less than zero, greater than total available<br />
if((!$page) || (is_numeric($page) == false) || ($page  $total_items)) {<br />
      $page = 1; //default<br />
}</p>
<p>//calcuate total pages<br />
$total_pages = ceil($total_items / $limit);<br />
$set_limit = ($page * $limit) - $limit;</p>
<p>echo '' . $set_limit . '';</p>
<p>//query: **EDIT TO YOUR TABLE NAME, ECT.</p>
<p>$q = mysql_query("SELECT * FROM `users` LIMIT $set_limit, $limit");<br />
if(!$q) die(mysql_error());<br />
if(mysql_num_rows($q) == 0) die('No matches met your criteria.');</p>
<p>//Results per page: **EDIT LINK PATH**<br />
 echo('<br />
 <a href="http://localhost/Code-Test/pagination/pagination.php?limit=10&amp;page=1" rel="nofollow">10</a> |<br />
 <a href="http://localhost/Code-Test/pagination/pagination.php?limit=25&amp;page=1" rel="nofollow">25</a> |<br />
 <a href="http://localhost/Code-Test/pagination/pagination.php?limit=50&amp;page=1" rel="nofollow">50</a><br />
 ');</p>
<p>//show data matching query:<br />
while($code = mysql_fetch_object($q)) {<br />
  //print your data here.<br />
echo('————————————–');<br />
echo('Name: '.$code-&gt;username.'');<br />
echo('Math Marks: '.$code-&gt;email.'');<br />
echo('Physics Marks: '.$code-&gt;usertype.'');<br />
echo('————————————–');<br />
}</p>
<p>//prev. page: **EDIT LINK PATH**</p>
<p>$prev_page = $page - 1;</p>
<p>if($prev_page &gt;= 1) {<br />
  echo('<b>&lt;&lt;</b> <a href="http://localhost/Code-Test/pagination/pagination.php?limit=$limit&amp;page=$prev_page" rel="nofollow"><b>Prev.</b></a>');<br />
}</p>
<p>//Display middle pages: **EDIT LINK PATH**</p>
<p>for($a = 1; $a &lt;= $total_pages; $a++)<br />
{<br />
   if($a == $page) {<br />
      echo("<b> $a</b> | "); //no link<br />
     } else {<br />
  echo("  <a href="http://localhost/Code-Test/pagination/pagination.php?limit=$limit&amp;page=$a" rel="nofollow"> $a </a> | ");<br />
     }<br />
}</p>
<p>//next page: **EDIT THIS LINK PATH**</p>
<p>$next_page = $page + 1;<br />
if($next_page &lt;= $total_pages) {<br />
   echo("<a href="http://localhost/Code-Test/pagination/pagination.php?limit=$limit&amp;page=$next_page" rel="nofollow"><b>Next</b></a> &gt; &gt;");<br />
}</p>
<p>//all done<br />
?&gt;<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ranacse05</title>
		<link>http://usefulscripts.wordpress.com/2007/10/26/pagination-using-php-mysql/#comment-36</link>
		<dc:creator>ranacse05</dc:creator>
		<pubDate>Wed, 09 Apr 2008 02:14:30 +0000</pubDate>
		<guid isPermaLink="false">http://usefulscripts.wordpress.com/2007/10/26/pagination-using-php-mysql/#comment-36</guid>
		<description>Help full script :)</description>
		<content:encoded><![CDATA[<p>Help full script <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
