solon Posted December 23, 2008 Share Posted December 23, 2008 Hey guys i need to know if there is a way to access the previous row in a table if the "id" field is messed up because of a different SORTING (order by "another field") Thanks in advance Link to comment https://forums.phpfreaks.com/topic/138177-solved-query-problems/ Share on other sites More sharing options...
ngreenwood6 Posted December 23, 2008 Share Posted December 23, 2008 maybe you can clarify but if i am reading this correctly you could do something like this: $id = 3 $id = $id -1 $query = "SELECT * FROM table WHERE id='$id'"; All that basically does is take id and change it from 3 to 2 so it just changes it to the row before if that is what you are talking about. if not please clarify. Link to comment https://forums.phpfreaks.com/topic/138177-solved-query-problems/#findComment-722298 Share on other sites More sharing options...
solon Posted December 23, 2008 Author Share Posted December 23, 2008 Ok the thing is that the rows in the table after the sorting are not sorted based on a number. They are based on Text so it's alphabetical order. Thats why i cant use your solution... Link to comment https://forums.phpfreaks.com/topic/138177-solved-query-problems/#findComment-722314 Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 Only by making another call to the database. Say your list is sorted and you have record 72. In your sorted list that may be the 41st in the list. Just run another query on the database pulling the previous record out by what you have - if that makes sense. Link to comment https://forums.phpfreaks.com/topic/138177-solved-query-problems/#findComment-722317 Share on other sites More sharing options...
solon Posted December 23, 2008 Author Share Posted December 23, 2008 i think i got your point. give me a min to check it out! Link to comment https://forums.phpfreaks.com/topic/138177-solved-query-problems/#findComment-722323 Share on other sites More sharing options...
ngreenwood6 Posted December 23, 2008 Share Posted December 23, 2008 yeah I would just make another query that would pull the id from the first query and do like I had told you and make another query to select the id from the previous one. Link to comment https://forums.phpfreaks.com/topic/138177-solved-query-problems/#findComment-722329 Share on other sites More sharing options...
solon Posted December 23, 2008 Author Share Posted December 23, 2008 Guys unfortunately i still have the same problem. I think that i need to solve through mysql. Thanks anyway for your help! Link to comment https://forums.phpfreaks.com/topic/138177-solved-query-problems/#findComment-722334 Share on other sites More sharing options...
ngreenwood6 Posted December 23, 2008 Share Posted December 23, 2008 if you post your code we can be of more help. Link to comment https://forums.phpfreaks.com/topic/138177-solved-query-problems/#findComment-722346 Share on other sites More sharing options...
solon Posted December 23, 2008 Author Share Posted December 23, 2008 I 've got it guys, I just have to assign to a variable the value i want to check and then make the if statement, Thanks Link to comment https://forums.phpfreaks.com/topic/138177-solved-query-problems/#findComment-722444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.