04182005 1649 GMT-6 Ok. Odd thing here. I have only three records that im testing with. But this is actually skipping one.
function NextAppID($currentappid) { include ('db.php'); $sql ="SELECT MAX(appid) AS next FROM application WHERE appid > '".$currentappid."'"; $result = mysql_query($sql); if ($result) { $id = mysql_num_rows($result); if ($id){ $nextAppID = mysql_result($result,0,0); } } return $nextAppID; } My first one is 1 and the next it pulls is 3. Wade Patrick Bierans wrote: > it uses > "higher" and < "lower" so it doesn't matter if the exact > matching > row exists. > > ----- Original Message ----- > From: "Wade" <[EMAIL PROTECTED]> > To: <php-list@yahoogroups.com> > Sent: Monday, April 18, 2005 11:07 PM > Subject: Re: [php-list] Next & Previous Records > > > > 04182005 1606 GMT-6 > > > > Patrick, question on this. Im thinking that this only will work when you > > have consecutive numbering of application id's like, 1, 2, 3, 4, and so > > on. What if you have deleted a number = 1, 4, 5, 8,9,10 = would this > > still work? > > > > Wade > > > > > > > > Patrick Bierans wrote: > > > >> I think it's a wrapping thing. If reaching the end start from > beginning. > >> > >> ----- Original Message ----- > >> From: "Wade" <[EMAIL PROTECTED]> > >> To: <php-list@yahoogroups.com> > >> Sent: Monday, April 18, 2005 10:57 PM > >> Subject: [php-list] Next & Previous Records > >> > >> > >> > 04182005 1551 GMT-6 > >> > > >> > I want to find the next and previous records in a list of records. I > >> > did > >> > a search and found this code: > >> > > >> > $q1 = "SELECT Max(clrId ) As prev from tblcolorpattern Where clrId < > >> > $id"; > >> > $res = mysql_query($q1); > >> > if($res) > >> > { > >> > $num = mysql_num_rows($res); > >> > if($num) > >> > { > >> > $prev = mysql_result($res,0,0); > >> > } > >> > } > >> > > >> > this code give me id before the current id in DB > >> > > >> > /************************************************/ > >> > > >> > $q2 = "SELECT Min(clrId ) As next from tblcolorpattern Where clrId > > >> > $id"; > >> > $res = mysql_query($q2); > >> > if($res) > >> > { > >> > $num = mysql_num_rows($res); > >> > if($num) > >> > { > >> > $next = mysql_result($res,0,0); > >> > } > >> > } > >> > this code give me id after the current id in DB > >> > > >> > But Im a but unsure of it all so I would like some help with it. Im > >> > going to change it to what I think I would write: > >> > > >> > $query = "$SELECT MAX(appid) AS prev FROM Application WHERE appid < > >> > '".$appid."'"; > >> > > >> > $result = mysql_query($query); > >> > > >> > if($result) { > >> > $num = mysql_num_rows($result); > >> > > >> > if($num) { > >> > $next = mysql_result($result,0,0); > >> > } > >> > } > >> > > >> > Ok. Im selecting the next larger appid (application id) and > assigning > >> > it > >> > to 'prev'. > >> > > >> > Then, im assigning the appid to $num. > >> > I dont understand the next part at all = ($result,0,0); > >> > > >> > Wade > >> > > >> > > >> > [Non-text portions of this message have been removed] > >> > > >> > > >> > > >> > Community email addresses: > >> > Post message: php-list@yahoogroups.com > >> > Subscribe: [EMAIL PROTECTED] > >> > Unsubscribe: [EMAIL PROTECTED] > >> > List owner: [EMAIL PROTECTED] > >> > > >> > Shortcut URL to this page: > >> > http://groups.yahoo.com/group/php-list > >> > > >> > > >> > > >> > > >> > -------------------------------------------------------------------------------- > >> > Yahoo! Groups Links > >> > > >> > a.. To visit your group on the web, go to: > >> > http://groups.yahoo.com/group/php-list/ > >> > > >> > b.. To unsubscribe from this group, send an email to: > >> > [EMAIL PROTECTED] > >> > > >> > c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of > >> Service. > >> > > >> > > >> > >> > >> > >> Community email addresses: > >> Post message: php-list@yahoogroups.com > >> Subscribe: [EMAIL PROTECTED] > >> Unsubscribe: [EMAIL PROTECTED] > >> List owner: [EMAIL PROTECTED] > >> > >> Shortcut URL to this page: > >> http://groups.yahoo.com/group/php-list > >> > >> > >> > ------------------------------------------------------------------------ > >> *Yahoo! Groups Links* > >> > >> * To visit your group on the web, go to: > >> http://groups.yahoo.com/group/php-list/ > >> > >> * To unsubscribe from this group, send an email to: > >> [EMAIL PROTECTED] > >> <mailto:[EMAIL PROTECTED]> > >> > >> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of > >> Service <http://docs.yahoo.com/info/terms/>. > >> > >> > >>------------------------------------------------------------------------ > >> > >>No virus found in this incoming message. > >>Checked by AVG Anti-Virus. > >>Version: 7.0.308 / Virus Database: 266.9.16 - Release Date: 4/18/2005 > >> > >> > > > > > > [Non-text portions of this message have been removed] > > > > > > > > Community email addresses: > > Post message: php-list@yahoogroups.com > > Subscribe: [EMAIL PROTECTED] > > Unsubscribe: [EMAIL PROTECTED] > > List owner: [EMAIL PROTECTED] > > > > Shortcut URL to this page: > > http://groups.yahoo.com/group/php-list > > > > > > > > > -------------------------------------------------------------------------------- > > Yahoo! Groups Links > > > > a.. To visit your group on the web, go to: > > http://groups.yahoo.com/group/php-list/ > > > > b.. To unsubscribe from this group, send an email to: > > [EMAIL PROTECTED] > > > > c.. Your use of Yahoo! Groups is subject to the Yahoo! Terms of > Service. > > > > > > > > Community email addresses: > Post message: php-list@yahoogroups.com > Subscribe: [EMAIL PROTECTED] > Unsubscribe: [EMAIL PROTECTED] > List owner: [EMAIL PROTECTED] > > Shortcut URL to this page: > http://groups.yahoo.com/group/php-list > > > ------------------------------------------------------------------------ > *Yahoo! Groups Links* > > * To visit your group on the web, go to: > http://groups.yahoo.com/group/php-list/ > > * To unsubscribe from this group, send an email to: > [EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]> > > * Your use of Yahoo! Groups is subject to the Yahoo! Terms of > Service <http://docs.yahoo.com/info/terms/>. > > >------------------------------------------------------------------------ > >No virus found in this incoming message. >Checked by AVG Anti-Virus. >Version: 7.0.308 / Virus Database: 266.9.16 - Release Date: 4/18/2005 > > [Non-text portions of this message have been removed] Community email addresses: Post message: php-list@yahoogroups.com Subscribe: [EMAIL PROTECTED] Unsubscribe: [EMAIL PROTECTED] List owner: [EMAIL PROTECTED] Shortcut URL to this page: http://groups.yahoo.com/group/php-list Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/php-list/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/