Jump to content

Order items in a database by an order_id


toyfruit

Recommended Posts

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?

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

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.