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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.