membot Posted May 20, 2011 Share Posted May 20, 2011 Sorry if this belongs in the MySQL section. I figured it might be more of a PHP thing. I have a database where rows each have a number, which is used to determine what order they appear in on my PHP page. But right now they aren't like 1, 2, 3, 4, etc. They are a little jumbled because of deleting some and changing some, so they're more like 1, 3, 7, etc. Is there a way to make them 1, 2, 3, 4 with PHP? Like, put them in order and number them accordingly? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/236991-numbering-rows-in-a-database/ Share on other sites More sharing options...
mikosiko Posted May 20, 2011 Share Posted May 20, 2011 the famous question again.... we should have an Sticky post for this... short answer: Don't do it!!. for long answers/explanations just do a search in this forum using "renumber" Quote Link to comment https://forums.phpfreaks.com/topic/236991-numbering-rows-in-a-database/#findComment-1218139 Share on other sites More sharing options...
membot Posted May 20, 2011 Author Share Posted May 20, 2011 Well the thing is, I'm making an admin for the site, so the user will see these numbers and be able to change them. The idea is that if for example they want to put in a new row between rows 2 and 3, they could type 2.5 for the row number. Then when they save it and refresh the page, the rows are ordered with integers again. I've seen this exact thing done on other sites. Maybe it's not very efficient, but it'll do for me. Quote Link to comment https://forums.phpfreaks.com/topic/236991-numbering-rows-in-a-database/#findComment-1218149 Share on other sites More sharing options...
mikosiko Posted May 20, 2011 Share Posted May 20, 2011 well... if the field that hold those numbers that you are referring to is not a Primary Key (PK) or part of a relation with other table (Foreign Key) then ... yes... you could renumber as you wish. Quote Link to comment https://forums.phpfreaks.com/topic/236991-numbering-rows-in-a-database/#findComment-1218167 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.