adding content to an array in PHP
- Started
- Last post
- 9 Responses
- graham414
Hi I am trying to add a record to a database and re-sort the values.
My array is split into a matrix so my main goal here is not having too much going on inside of the script but I would like to have the record inserted at an index i guess you could say.
Any good links or ideas this fine morning?
thanks
- armsbottomer0
Sorry, i'm a bit slow this morning. You're trying to insert the values of an array into a MySQL database and resort them?
- graham4140
Naw I have a database, and on the backend I want to create a sortable list where the first record in the list doesnt move, but every other record replaces itself. there are 2 ids a sortedid and an id.
right now I am reading this i dont know how I could use this in my situation.
- graham4140
Ah too much coffee, I am trying to work with mysql, I just need to update and add to the ID while moving the rest of the results down the list.
I am guessing I need to somehow do an Update id etc
Any ideas?
- heavyt0
generally, updating an ID column is a bad practice. You are better off using a new column to act as your sort. Eg. priority. Then you can easily update that column without doing a lot of messing around.
If you were to update an Id column, you would find that it needs to be unique, so you'd have to change them all twice in order to really shuffle them.
- graham4140
hrmm, i have 2 tables id and sortedid
Any good links floating around?
I been looking at MYSQL update and insert but in my situation I need to be able to add records and manipulate the ids
- drgss0
ok thats not the same as "array in php"
- graham4140
i undersand but id probably waste more time creating a new thread.
I just wanna figure out how to change the ids and move the rest of the info down the list.
I was so tired of searching i couldnt even eat my lunch today so now im really sad :-(
- acescence0
you're thinking about this the wrong way. you don't want to update every record in the db every time you insert or remove one. that is extremely inefficient.
- graham4140
Man i hate the game i just play it to play.
Im thinking imma have to make some script that says update blah blah blah where the ID of blah is not equal to 0 then replace id of blah2 with blah1 and resort.