Jump to content

might be a tuffy :(


Demonic

Recommended Posts

Alright you know you order stuff by ids say you make a posting script and you order them by ID how could you rearange the ordering without messing with the post id's?

say you have 4 cats order by id ASC
1
2
3
4

how would i order then like this

3
2
4
1
?

anybody have any suggestions its done on almost all forum systems.
Link to comment
https://forums.phpfreaks.com/topic/19845-might-be-a-tuffy/
Share on other sites

thats the problem i dont know how to order them since you can only have 1 auto_increment per table

i want to order my categorys in a different way

my sql is like this mysql_query("SELECT * FROM table order by id DESC")
simple enough

they come in order like this
cat 1
cat 2
cat 3

but i want to rearange them in some sort of fasion so they order by some number

like say i had the rearanging script now all cat's would be ordered like this:
cat 3
cat 1
cat 2

see what i mean i need to find a way on how to order the categories threw a form and update them is it possible to give alter tables and make a default number until its updated threw the form and order them that way?
say i alter the catgory table and make default 1 so all new cats will be 1 until thier updated then i want to order by that number. Very hard to explain since im not great with explaining nothen.

ALTER TABLE `categories` ADD `order` INT( 10 ) NOT NULL DEFAULT '1' AFTER `id`  and all are 1 right now :) <didnt work :(
Link to comment
https://forums.phpfreaks.com/topic/19845-might-be-a-tuffy/#findComment-86879
Share on other sites

You would need to create a specific field (order_by) with which you can specify whatever order you want your records to appear. eg

[code]
id    order_by
__________________
1    3
2    6
3    1
4    5
5    2
6    4
[/code]

Given th above example, the following query...

[code]
SELECT id FROM tbl ORDER BY order_by
[/code]

would produce...

[code]
id
___________________
3
5
1
6
4
2
[/code]

Does that help explain it?
Link to comment
https://forums.phpfreaks.com/topic/19845-might-be-a-tuffy/#findComment-86896
Share on other sites

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.