Click here to get back home

saving sequence order of files

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
saving sequence order of files php_mysql_beginer911 07-12-2008
Posted by php_mysql_beginer911 on July 12, 2008, 1:44 am
Please log in for more thread options
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
$i=1
foreah($new_seq as $seq)

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

$i++;
}

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.

thanks


Posted by C. (http://symcbean.blogspot.c on July 13, 2008, 7:33 am
Please log in for more thread options
> 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
> $i=1
> foreah($new_seq as $seq)
>
> $sql="UPDATE table SET sequence=$seq[$i]";
> mysql_query($sql) or die(mysql_error());
>
> $i++;
>
> }
>
> 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.
>
> thanks

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.

HTH

C.

Posted by php_mysql_beginer911 on July 13, 2008, 9:53 am
Please log in for more thread options
Hi HTH,
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
db
i am using jquery plugin for drag and drop.. may be if you can see the
page you can understand better

http://www.isocra.com/2008/02/table-drag-and-drop-jquery-plugin/

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



Posted by Jerry Stuckle on July 13, 2008, 10:29 am
Please log in for more thread options
php_mysql_beginer911 wrote:
> Hi HTH,
> 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
> db
> i am using jquery plugin for drag and drop.. may be if you can see the
> page you can understand better
>
> http://www.isocra.com/2008/02/table-drag-and-drop-jquery-plugin/
>
> 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
>
>
>

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.
jstucklex@attglobal.net
==================


Posted by php_mysql_beginer911 on July 13, 2008, 11:48 am
Please log in for more thread options
Thanks Jerry for replying and for your suggestion.
hope i can find something from comp.databases.mysql.
thanks again


Similar ThreadsPosted
2 methods of including files sequence June 23, 2007, 1:21 pm
saving uploading files on the server July 20, 2004, 7:42 am
Saving Temp Files in Shared Memory November 28, 2005, 7:33 am
PEAR DB: How do I set the value of a sequence? July 15, 2004, 12:20 pm
Pseudo Random Sequence November 10, 2005, 5:28 pm
executing a sequence of mysql statements May 4, 2005, 2:04 am
Removing elements from an array -- key sequence ... March 19, 2006, 3:56 pm
generate 2 random numbers in rapid sequence April 22, 2006, 8:58 pm
reading the correct line sequence from a txt file April 10, 2007, 3:52 am
creating a cumulative total column, but not in sequence December 27, 2007, 3:09 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap