saving sequence order of files

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
hi i am trying to save a order of files where on submit
i am updating a field in a loop

$new_seq=$_POST['seq']; // array of seq hidden input field -name=seq[]
in form
foreah($new_seq as $seq)

$sql="UPDATE table SET sequence=$seq[$i]";
mysql_query($sql) or die(mysql_error());


do you think this is the best way of saving order list of files or is
there any other way..
i thought of only updating those fields which were changed by
comparing with old values before loop
but not really sure if it will work ..please reply if you think we can
do this in a better and shorter way.


Re: saving sequence order of files

Quoted text here. Click to load it

I'm not sure I understand what you're asking.

You certainly should not rely on the sequence number provided from the
user as being in any way valid - all they need to do is tamper with
the request to start overwriting data. Unless of course, the object of
the exercise is to define a sequence of files which already exist.

A lot of the question depends on the significance of the sequence
number and how it is generated. MySQL insert ids are convenient but
don't work very well with parallel database servers.

If the objective is simply to tag files with an indicator to reference
other data then a better solution would be to use the md5 or sha1 hash
of the file.



Re: saving sequence order of files

thanks for the answer ...
i am sorry for my poor english .. as i am not a native speaker.
i hope i can explain better this time..

so here i go again ..

i have page where i can see the list of files which are in db and
allready have sequence numbers like 1,2,3.... which i can use to order
them by using mysql oreder by .. i am using drag and drop so i can
rearrange the file sequences that means if i want to see the first
file in 2nd row i will simply drag it to the 2nd row and hit the
update button which will update the sequence field with new value in
i am using jquery plugin for drag and drop.. may be if you can see the
page you can understand better /

in  simple words i am updating the new file sequence after i am done
changing its old position by using drag and drop feature .... and i am
updating it with new values (using file_id[] hidden field which
contents file_id and new sequence number which i can get from table
row id by using jquery plugin )that means if there are 300 files than
my mysql update query will run 300 times .. all i am wondering is that
is there a better way to do this .. which can improve the
performance .. all i can think is that not updating those sequence
fields which were not changed by comparing them with old values when i
am doing the update in a loop .

hope my explanation is not confusing ...
and thanks again for giving your precious time to this post

Re: saving sequence order of files

php_mysql_beginer911 wrote:
Quoted text here. Click to load it

 From the PHP end, there isn't much you can do other than check against
the old value and not UPDATE if they are the same.  Of course. there are
various ways to do this - i.e. if you move a file from position 6 to
position 2, you can easily determine only the old positions 2-6 need to
be changed.

But depending on how you do thing, there might be mysql ways of doing it
also.  Try comp.databases.mysql for suggestions.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: saving sequence order of files

Thanks Jerry for replying and for your suggestion.
hope i can find something from comp.databases.mysql.
thanks again

Re: saving sequence order of files

Quoted text here. Click to load it

I'm not going to go learn how to implement it myself using jquery, but
surely when populating you can store an original sequence number
within the data which is being manipulated - then when yopu receive
the data back from jquery you compare the current position with the
embedded position to work out which you need to move.



Site Timeline