Gruzin Posted November 11, 2006 Share Posted November 11, 2006 Hi guys,Here is my question: Is it possible to move up/down a record in table using php? If yes how can I do that?Thanks,George Quote Link to comment https://forums.phpfreaks.com/topic/26952-phpmysql-question/ Share on other sites More sharing options...
chiprivers Posted November 11, 2006 Share Posted November 11, 2006 Do you mean when displaying your results or literally the order in which the records are stored in the database? Quote Link to comment https://forums.phpfreaks.com/topic/26952-phpmysql-question/#findComment-123237 Share on other sites More sharing options...
Gruzin Posted November 11, 2006 Author Share Posted November 11, 2006 I'd like to move one record up with one step in db.....Thanks,George Quote Link to comment https://forums.phpfreaks.com/topic/26952-phpmysql-question/#findComment-123238 Share on other sites More sharing options...
chiprivers Posted November 11, 2006 Share Posted November 11, 2006 I think what your asking to do is swap the position two records are stored in the actual database, what you will have to do is extract the values of each field from both the records and then update each record with the other records values, excluding the primary key field. This will then have the effect of swapping them around, I think! Quote Link to comment https://forums.phpfreaks.com/topic/26952-phpmysql-question/#findComment-123248 Share on other sites More sharing options...
Gruzin Posted November 11, 2006 Author Share Posted November 11, 2006 [quote author=chiprivers link=topic=114659.msg466593#msg466593 date=1163276806]I think what your asking to do is swap the position two records are stored in the actual database, what you will have to do is extract the values of each field from both the records and then update each record with the other records values, excluding the primary key field. This will then have the effect of swapping them around, I think![/quote]That's what i thought, thanks freind ;) Quote Link to comment https://forums.phpfreaks.com/topic/26952-phpmysql-question/#findComment-123251 Share on other sites More sharing options...
chiprivers Posted November 11, 2006 Share Posted November 11, 2006 It would be easier if you could swap the value of the primary key field but I don't think you can do that. Quote Link to comment https://forums.phpfreaks.com/topic/26952-phpmysql-question/#findComment-123258 Share on other sites More sharing options...
lixid Posted November 11, 2006 Share Posted November 11, 2006 well i might be wrong .. but you could always set up and id field w/ auto increment and then set up the code to change the # of the id field from say 5 to 2 but then you would have to change the id field of 2 to 5 .. im sure it would be hard to setup .. but you might be able to create some type of counter that would decrease and increase the field number at the same time .. that kind of thing .. but i could be wrong .. :] but as chiprivers said you might not be able to do it with the primary key ... Quote Link to comment https://forums.phpfreaks.com/topic/26952-phpmysql-question/#findComment-123262 Share on other sites More sharing options...
Gruzin Posted November 11, 2006 Author Share Posted November 11, 2006 Thanks guys, I'll try that ;) Quote Link to comment https://forums.phpfreaks.com/topic/26952-phpmysql-question/#findComment-123265 Share on other sites More sharing options...
Psycho Posted November 11, 2006 Share Posted November 11, 2006 If you build your database correctly you should NEVER need to rearrange the order the records actually exist in the database. Quote Link to comment https://forums.phpfreaks.com/topic/26952-phpmysql-question/#findComment-123278 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.