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.. 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 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 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 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. 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. Link to comment https://forums.phpfreaks.com/topic/34972-query-question/#findComment-165086 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.