corillo181 Posted January 20, 2007 Share Posted January 20, 2007 why is this query work fine [code]$sel=mysql_query("SELECT photo_id FROM tra_photo WHERE album_id='".$_GET['a']."' AND photo_id>'$foto_id'")or die(mysql_error());$back=mysql_fetch_array($sel);[/code]but this one doesn't[code]$sel=mysql_query("SELECT photo_id FROM tra_photo WHERE album_id='".$_GET['a']."' AND photo_id<'$foto_id'")or die(mysql_error());$next=mysql_fetch_array($sel);[/code]the next link sends me to the first id instead of the next id from wich ever is selected at the time.. Quote Link to comment https://forums.phpfreaks.com/topic/34972-query-question/ Share on other sites More sharing options...
hvle Posted January 20, 2007 Share Posted January 20, 2007 2 query is exactly same, and therefore it must return exact result and that's why your $next is same as your $back Quote Link to comment https://forums.phpfreaks.com/topic/34972-query-question/#findComment-164961 Share on other sites More sharing options...
PC Nerd Posted January 20, 2007 Share Posted January 20, 2007 well the only difference between the two querys physically is the < versus the > in the photo id section i think Quote Link to comment https://forums.phpfreaks.com/topic/34972-query-question/#findComment-164963 Share on other sites More sharing options...
Daniel0 Posted January 20, 2007 Share Posted January 20, 2007 Try: [code]$sel = mysql_query("SELECT photo_id FROM tra_photo WHERE album_id='".$_GET['a']."' AND photo_id=photo_id-1")or die(mysql_error());$back = mysql_fetch_array($sel);$sel = mysql_query("SELECT photo_id FROM tra_photo WHERE album_id='".$_GET['a']."' AND photo_id=photo_id+1")or die(mysql_error());$next = mysql_fetch_array($sel);[/code] instead Quote Link to comment https://forums.phpfreaks.com/topic/34972-query-question/#findComment-164968 Share on other sites More sharing options...
corillo181 Posted January 20, 2007 Author Share Posted January 20, 2007 i can't use +1 or -1.. becuase it goes down to the next id..if i'm in id 20 and i put 20-1=19 if 19 belongs to another album id it wont show nothing. Quote Link to comment https://forums.phpfreaks.com/topic/34972-query-question/#findComment-165084 Share on other sites More sharing options...
.josh Posted January 20, 2007 Share Posted January 20, 2007 it is giving you the 1st one because by default mysql orders by ascending order. tack on an "order by desc" on the end of your "back" query. Quote Link to comment https://forums.phpfreaks.com/topic/34972-query-question/#findComment-165086 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.