<?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: PHP-MySql: Select previous row and next row from current ID</title>
	<atom:link href="http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/</link>
	<description>Fight for what you belive in</description>
	<lastBuildDate>Thu, 02 Feb 2012 06:38:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: deepak</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-2/#comment-40755</link>
		<dc:creator>deepak</dc:creator>
		<pubDate>Tue, 31 Jan 2012 09:03:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-40755</guid>
		<description>for anchor tag, what code code i used to disable the already exist anchor in php when all record empty in database</description>
		<content:encoded><![CDATA[<p>for anchor tag, what code code i used to disable the already exist anchor in php when all record empty in database</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesús Cepeda Cid</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-1/#comment-40109</link>
		<dc:creator>Jesús Cepeda Cid</dc:creator>
		<pubDate>Thu, 12 Jan 2012 20:44:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-40109</guid>
		<description>After a couple of hours with a BACK NEXT problem to show results on a particular query you gave me the  cleanest solution ever. 
Tons of thanks</description>
		<content:encoded><![CDATA[<p>After a couple of hours with a BACK NEXT problem to show results on a particular query you gave me the  cleanest solution ever.<br />
Tons of thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-1/#comment-39564</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 03 Jan 2012 15:22:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-39564</guid>
		<description>Some thing happened to the less-than symbol:

the second WHERE should be:

WHERE time &lt;</description>
		<content:encoded><![CDATA[<p>Some thing happened to the less-than symbol:</p>
<p>the second WHERE should be:</p>
<p>WHERE time &lt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-1/#comment-39563</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 03 Jan 2012 15:15:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-39563</guid>
		<description>SELECT id
FROM posts
WHERE time = (SELECT MIN(time)
	FROM posts
	WHERE time &gt;
		(SELECT time
		FROM posts
		WHERE id = $id))</description>
		<content:encoded><![CDATA[<p>SELECT id<br />
FROM posts<br />
WHERE time = (SELECT MIN(time)<br />
	FROM posts<br />
	WHERE time &gt;<br />
		(SELECT time<br />
		FROM posts<br />
		WHERE id = $id))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-1/#comment-39562</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 03 Jan 2012 15:14:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-39562</guid>
		<description>With one query that returns three values (or two if its the last row): last, current and next. It only fails if the value of id is the first row. If you get an empty return value, just execute the following to get the id of the second row:

(see next post)</description>
		<content:encoded><![CDATA[<p>With one query that returns three values (or two if its the last row): last, current and next. It only fails if the value of id is the first row. If you get an empty return value, just execute the following to get the id of the second row:</p>
<p>(see next post)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-1/#comment-39561</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 03 Jan 2012 15:13:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-39561</guid>
		<description>That chopped off the rest of the query. Here&#039;s the rest:

ORDER BY time ASC
LIMIT 3</description>
		<content:encoded><![CDATA[<p>That chopped off the rest of the query. Here&#8217;s the rest:</p>
<p>ORDER BY time ASC<br />
LIMIT 3</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-1/#comment-39560</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 03 Jan 2012 15:11:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-39560</guid>
		<description>Here&#039;s what I came up with for ordering by a separate field (time):

SELECT id
FROM posts
WHERE time &gt;= (SELECT MAX(time)
	FROM posts
	WHERE time 
		(SELECT time
		FROM posts
		WHERE id = $id))</description>
		<content:encoded><![CDATA[<p>Here&#8217;s what I came up with for ordering by a separate field (time):</p>
<p>SELECT id<br />
FROM posts<br />
WHERE time &gt;= (SELECT MAX(time)<br />
	FROM posts<br />
	WHERE time<br />
		(SELECT time<br />
		FROM posts<br />
		WHERE id = $id))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-1/#comment-39557</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 03 Jan 2012 13:50:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-39557</guid>
		<description>Unfortunately that&#039;s not true. If you order by time, for instance, the id may be less than the given id while the time could be greater. I believe a subquery would be necessary.</description>
		<content:encoded><![CDATA[<p>Unfortunately that&#8217;s not true. If you order by time, for instance, the id may be less than the given id while the time could be greater. I believe a subquery would be necessary.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mohey</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-1/#comment-39499</link>
		<dc:creator>Mohey</dc:creator>
		<pubDate>Mon, 02 Jan 2012 13:54:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-39499</guid>
		<description>thnx</description>
		<content:encoded><![CDATA[<p>thnx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Agustín Amenabar</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-1/#comment-37476</link>
		<dc:creator>Agustín Amenabar</dc:creator>
		<pubDate>Sun, 06 Nov 2011 20:59:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-37476</guid>
		<description>BRRILLIANT!!! you sir saved me hours.</description>
		<content:encoded><![CDATA[<p>BRRILLIANT!!! you sir saved me hours.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bade Lal Verma</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-1/#comment-36838</link>
		<dc:creator>Bade Lal Verma</dc:creator>
		<pubDate>Tue, 27 Sep 2011 13:45:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-36838</guid>
		<description>// Prev id
   $sql2 = &quot;SELECT * FROM user_login WHERE id 0) {
        $prevrow = mysql_fetch_assoc($result2);
	//	echo &#039;&#039;. print_r($prevrow,true) . &#039;&#039;;
		$previd=$prevrow[&#039;id&#039;];
	//	echo &quot;Prev = &quot;.$previd.&quot;&quot;;
    }
	
	 // Next id
    $sql1 = &quot;SELECT * FROM user_login WHERE id &gt; {$curid} LIMIT 1&quot;;
	
    $result1 = mysql_query($sql1);
    if (mysql_num_rows($result1)&gt;0) {
        $nextrow = mysql_fetch_assoc($result1);
	//	echo &#039;&#039;. print_r($nextrow,true) . &#039;&#039;;
		$nextid=$nextrow[&#039;id&#039;];
	//	echo &quot;Next = &quot;.$nextid.&quot;&quot;;
    }</description>
		<content:encoded><![CDATA[<p>// Prev id<br />
   $sql2 = &#8220;SELECT * FROM user_login WHERE id 0) {<br />
        $prevrow = mysql_fetch_assoc($result2);<br />
	//	echo &#8221;. print_r($prevrow,true) . &#8221;;<br />
		$previd=$prevrow['id'];<br />
	//	echo &#8220;Prev = &#8220;.$previd.&#8221;";<br />
    }</p>
<p>	 // Next id<br />
    $sql1 = &#8220;SELECT * FROM user_login WHERE id &gt; {$curid} LIMIT 1&#8243;;</p>
<p>    $result1 = mysql_query($sql1);<br />
    if (mysql_num_rows($result1)&gt;0) {<br />
        $nextrow = mysql_fetch_assoc($result1);<br />
	//	echo &#8221;. print_r($nextrow,true) . &#8221;;<br />
		$nextid=$nextrow['id'];<br />
	//	echo &#8220;Next = &#8220;.$nextid.&#8221;";<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bade Lal Verma</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-1/#comment-36837</link>
		<dc:creator>Bade Lal Verma</dc:creator>
		<pubDate>Tue, 27 Sep 2011 13:40:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-36837</guid>
		<description>Following is a complete code for displaying Current Record With Previous, Next Record button


0) {
		
        $info = mysql_fetch_assoc($result);
    } else {
        die(&#039;Not found&#039;);
    }

   

    // Prev id
   $sql2 = &quot;SELECT * FROM user_login WHERE id 0) {
        $prevrow = mysql_fetch_assoc($result2);
	//	echo &#039;&#039;. print_r($prevrow,true) . &#039;&#039;;
		$previd=$prevrow[&#039;id&#039;];
	//	echo &quot;Prev = &quot;.$previd.&quot;&quot;;
    }
	
	 // Next id
    $sql1 = &quot;SELECT * FROM user_login WHERE id &gt; {$curid} LIMIT 1&quot;;
	
    $result1 = mysql_query($sql1);
    if (mysql_num_rows($result1)&gt;0) {
        $nextrow = mysql_fetch_assoc($result1);
	//	echo &#039;&#039;. print_r($nextrow,true) . &#039;&#039;;
		$nextid=$nextrow[&#039;id&#039;];
	//	echo &quot;Next = &quot;.$nextid.&quot;&quot;;
    }
	
} else {
    // No form has been submitted so use the lowest id and grab its info
    $sql = &quot;SELECT id,username,password FROM user_login WHERE id &gt; 0&quot;;
	
    $result = mysql_query($sql);
    if (mysql_num_rows($result)&gt;0) {
		
        $info = mysql_fetch_assoc($result);
		
		$sql1 = &quot;SELECT * FROM user_login WHERE id &gt; {$info[&#039;id&#039;]} LIMIT 1&quot;;
	
		$result1 = mysql_query($sql1);
		if (mysql_num_rows($result1)&gt;0) {
			$nextrow = mysql_fetch_assoc($result1);
			$nextid=$nextrow[&#039;id&#039;];
		}
}
}
if (isset($info)) {
    $content = &#039;&#039;.print_r($info,true).&#039;&#039;;
	
} else {
    $content =  &#039;Nothing in the db :(&#039;;
}
?&gt;


Next prev


Info



&lt;input type=&quot;submit&quot; name=&quot;id[]&quot; value=&quot;prev&quot;/&gt;


&lt;input type=&quot;submit&quot; name=&quot;id[]&quot; value=&quot;next&quot;/&gt;



</description>
		<content:encoded><![CDATA[<p>Following is a complete code for displaying Current Record With Previous, Next Record button</p>
<p>0) {</p>
<p>        $info = mysql_fetch_assoc($result);<br />
    } else {<br />
        die(&#8216;Not found&#8217;);<br />
    }</p>
<p>    // Prev id<br />
   $sql2 = &#8220;SELECT * FROM user_login WHERE id 0) {<br />
        $prevrow = mysql_fetch_assoc($result2);<br />
	//	echo &#8221;. print_r($prevrow,true) . &#8221;;<br />
		$previd=$prevrow['id'];<br />
	//	echo &#8220;Prev = &#8220;.$previd.&#8221;";<br />
    }</p>
<p>	 // Next id<br />
    $sql1 = &#8220;SELECT * FROM user_login WHERE id &gt; {$curid} LIMIT 1&#8243;;</p>
<p>    $result1 = mysql_query($sql1);<br />
    if (mysql_num_rows($result1)&gt;0) {<br />
        $nextrow = mysql_fetch_assoc($result1);<br />
	//	echo &#8221;. print_r($nextrow,true) . &#8221;;<br />
		$nextid=$nextrow['id'];<br />
	//	echo &#8220;Next = &#8220;.$nextid.&#8221;";<br />
    }</p>
<p>} else {<br />
    // No form has been submitted so use the lowest id and grab its info<br />
    $sql = &#8220;SELECT id,username,password FROM user_login WHERE id &gt; 0&#8243;;</p>
<p>    $result = mysql_query($sql);<br />
    if (mysql_num_rows($result)&gt;0) {</p>
<p>        $info = mysql_fetch_assoc($result);</p>
<p>		$sql1 = &#8220;SELECT * FROM user_login WHERE id &gt; {$info['id']} LIMIT 1&#8243;;</p>
<p>		$result1 = mysql_query($sql1);<br />
		if (mysql_num_rows($result1)&gt;0) {<br />
			$nextrow = mysql_fetch_assoc($result1);<br />
			$nextid=$nextrow['id'];<br />
		}<br />
}<br />
}<br />
if (isset($info)) {<br />
    $content = &#8221;.print_r($info,true).&#8221;;</p>
<p>} else {<br />
    $content =  &#8216;Nothing in the db <img src='http://www.akemapa.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> &#8216;;<br />
}<br />
?&gt;</p>
<p>Next prev</p>
<p>Info</p>
<p>&lt;input type=&quot;submit&quot; name=&quot;id[]&#8221; value=&#8221;prev&#8221;/&gt;</p>
<p>&lt;input type=&quot;submit&quot; name=&quot;id[]&#8221; value=&#8221;next&#8221;/&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rob</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-1/#comment-36805</link>
		<dc:creator>rob</dc:creator>
		<pubDate>Fri, 23 Sep 2011 12:23:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-36805</guid>
		<description>Thanks! used it at my website. Easy to use!</description>
		<content:encoded><![CDATA[<p>Thanks! used it at my website. Easy to use!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mitta</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-1/#comment-36005</link>
		<dc:creator>Mitta</dc:creator>
		<pubDate>Mon, 15 Aug 2011 22:14:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-36005</guid>
		<description>I realy like your solution! this helps me alot.
btw, i like your way of explaining the scripts. keep it up!</description>
		<content:encoded><![CDATA[<p>I realy like your solution! this helps me alot.<br />
btw, i like your way of explaining the scripts. keep it up!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: robee</title>
		<link>http://www.akemapa.com/2008/07/15/php-mysql-select-previous-row-and-next-row-from-current-id/comment-page-1/#comment-35917</link>
		<dc:creator>robee</dc:creator>
		<pubDate>Thu, 04 Aug 2011 06:41:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.akemapa.com/?p=134#comment-35917</guid>
		<description>hi this is pretty neat. unlike on what i did to my project where i query all id and put these on an array variable then access it one by one. this will save me more time and resources. thanks ill try this right away.</description>
		<content:encoded><![CDATA[<p>hi this is pretty neat. unlike on what i did to my project where i query all id and put these on an array variable then access it one by one. this will save me more time and resources. thanks ill try this right away.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

