toyfruit Posted November 25, 2008 Share Posted November 25, 2008 Hi All I would like to have an 'order_id' number for each item in a table my database. I'd like to be able to then display the items by their order_id on my website. Within my CMS I would like to be able to reorder items as and when I want, (for example if my site has 5 items, if I add a new item, I would like to be able to add that item at the top of the other items; under a specific item; or at the bottom). So I may have: Item1 Item2 Item3 Item4 Item5 but then want to reorder them to display like: Item3 Item2 Item5 Item1 Item4 Can someone explain how I can order by order_id in the way shown above? Link to comment https://forums.phpfreaks.com/topic/134203-order-items-in-a-database-by-an-order_id/ Share on other sites More sharing options...
laPistola Posted November 25, 2008 Share Posted November 25, 2008 in your sql query add ORDER BY order_id ASC to change the order on page i normally set it as url var ie ORDER BY ".$_GET['order']." ".$_GET['ad']; then set the links to have the vars in the url to the page ir index.php?order=order_id&ad=DESC Link to comment https://forums.phpfreaks.com/topic/134203-order-items-in-a-database-by-an-order_id/#findComment-698570 Share on other sites More sharing options...
toyfruit Posted November 25, 2008 Author Share Posted November 25, 2008 Thanks - I think I get what you mean - can you explain how I can change the order_id of an item in the DB though, so say I have Item1 - order_id=1 Item2 - order_id=2 Item3 - order_id=3 and I want to change it to: Item1 - order_id=2 Item2 - order_id=1 Item3 - order_id=3 How can I get change the order_id number and have the other numbers update in relation to it? I'm not sure I'm making myself very clear, or maybe I'm not approaching this in the right way? Link to comment https://forums.phpfreaks.com/topic/134203-order-items-in-a-database-by-an-order_id/#findComment-698599 Share on other sites More sharing options...
toyfruit Posted November 25, 2008 Author Share Posted November 25, 2008 Anyone? Maybe there is a better way to approach this, I'd be happy to hear any thoughts Link to comment https://forums.phpfreaks.com/topic/134203-order-items-in-a-database-by-an-order_id/#findComment-698812 Share on other sites More sharing options...
revraz Posted November 25, 2008 Share Posted November 25, 2008 What reason would you need to chang the id? Link to comment https://forums.phpfreaks.com/topic/134203-order-items-in-a-database-by-an-order_id/#findComment-698817 Share on other sites More sharing options...
samja Posted November 25, 2008 Share Posted November 25, 2008 You need on an other field to your table. For example on id-field, that is uniq to all record. You can not change the order properly without above since when you change one item, there are not uniq records for next change. Link to comment https://forums.phpfreaks.com/topic/134203-order-items-in-a-database-by-an-order_id/#findComment-698822 Share on other sites More sharing options...
revraz Posted November 25, 2008 Share Posted November 25, 2008 Well yes and no. It would be best to have a Row ID, Description, Order to allow future growth, but if each item has a unique name it could in theory be used as well. But you would have to have logic to read it's current ID and then change it as well as the others that it affects. Link to comment https://forums.phpfreaks.com/topic/134203-order-items-in-a-database-by-an-order_id/#findComment-698828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.