php-mysql sorting question.
- Started
- Last post
- 8 Responses
- graham414
Hello, I have an issue where I want to insert records into a database and have the record inserted into a specific area of the db colum between 1(beginning or first record) & 3(last record in the array [possibly] and sort the record based on another column and update that cycle u could say.
Basically I am trying to do this
[section]
[record1]
[record2]
[record3]
[section]*now i update db and insert [record4] but I want [record3] to be replaced by [record4] yet have the items sorted.
I want to do this so I could have a way of managing sub contents in this database in order to have a backend that makes sense.
I really hope someone out there understood what I was trying to accomplish and somehow point me to some resources on the subject.
- TResudek0
I can most definitely help you but I can't understand what you are asking for.
- flavorful0
Hrm ... should you break these out into three tables?
01. Section
02. Record
03. Section_Record_LinkThat way you can have unique values in 01/02, and a unique relationship with their primary keys in 03. That way you wouldn't be bound to an array.
- Plus Records can then belong to multiple Sections.flavorful
- flavorful0
This doesn't make sense to me unfortunately, and I think I jumped the gun. Can you add a "num_Order" field, and simply update that appropriately during your SQL Update? And then bring back TOP 3 based on "num_Order ASC"?
- kingsteven0
Look up the SQL command "ORDER BY" Is that what you're looking for?
- n8w0
I wouldn't worry about how things are sorted in the database as far as order .. think in term of what you want to sort on and then build your sql statements accordingly.
Can you give an a real scenario of how you want users to interact with it?
I used the forum phpfreaks.com for this stuff ..
- graham4140
well basically on the backend the user would create a listing and that listing would be placed in a section where the sorted_id would append* to the current order of items in the array.
sorta like put this here and move everything else down the list.
- TResudek0
So you are saying you need to be able to sort items by a field? For example: You have three articles. You want to add a new article and you want it to be displayed 2nd in the list.
If that is the case, you need only add one field (ie. "priority") and let the user determine where each item goes. Then sort by that field when you make your query.
Is that helpful?
- graham4140
Man I would like to thank you guys for the help, I did a tutorial on PHP freaks and it gave me a better understanding.