Jump to content

MYSQL Question


eva21

Recommended Posts

Usually saving in a database, you have the field, and than the ID. Now since SQL increments on its own for example: 1, 2, 3,4 etc...usually when you call that certain table it displays as

1  - whatever

2  - whatever2

3 - whatever3

4 - whatever4

 

Unless specified. Now if I let the user to chance the fields around, and so now i need to it to show up like the following:

 

4 - whatever4

2  - whatever2

1  - whatever

3 - whatever3

 

What kind of SQL Statement would i do? I would have to do an UPDATE, but how could i make it save it in that order in the database?

Link to comment
Share on other sites

you'd need to do an update for each individual item, and what the query would actually look like is completely dependent upon the form you're using to let them change the order.

 

for the record, IDs are used to maintain referential integrity.  if you're just wanting to use it to order your results, you're better off just using an otherwise-named ("display_order" or something similar) with an INT format.  primary keys shouldn't be used for dictating display order.

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.