Find a sorting algorithm to save a bunch of files, and enter the path to the database, named after the number 123456... how can I write the algorithm to insert a file into it?
My idea is to call the path from the data, add a file name larger than the number of pages to be inserted, and then update the database file names in batches. However, the database does not respond after running. is this correct ??
The source code is as follows:
$ Newpage // New page number $ res = mysql_query ("select id, page from table by page asc"); while ($ arr = mysql_fetch_row ($ res )) {$ arr2 [$ arr [0] = $ arr [1];} $ count = count ($ arr2) + 1; for ($ I = $ newpage; $ I <$ count-$ newpage; $ I ++) {$ arr3 [$ I] = $ arr2 [$ I] + 1 ;} foreach ($ arr3 as $ k = >$ v) {$ q = mysql_query ("update table set page = case id when $ k then $ v ");}
Reply to discussion (solution)
$ Q = mysql_query ("update table set page = case id when $ k then $ v ");
What is then?
Sentence of case when... then...
Batch Upload
Does anyone know ??
1. the table structure and simple example are not very clear,
2. it seems that you don't have to worry about it. you should use simple SQL statements to achieve the effect of your current code.
3. if "the database does not respond after running", it should be an error, at least display the error information
I found that my algorithm is indeed faulty and I did not consider it in some cases.
In my current situation, the file name is named in a numerical sequence, such as 1, 2, 3, 4, and 5. the path is saved to the database. now I want to insert File 5 to the front of file 2, the original 2, 3, and 4 file names must be added to 1 accordingly. do you have any other good ideas or examples ?? I thought about it for a day. thank you.
Update... set num = num + 1 where num BETWEEN 2 and 5-1
Update... set num = 2 where num = 5
I tried it, but I still cannot.
That is, you did not describe the requirements clearly.
I have solved the problem by myself. thanks to the moderator, I want to write my own algorithms and help others.
If (! Empty ($ newpage) {/*** $ arr is the inserted array, and $ page is the current file name, $ newpage is the inserted page number */foreach ($ arr as $ k = >$ v) {if ($ v >=$ newpage & $ v <$ page + 1) {$ v = $ v + 1; $ q = mysql_query ("update table set page = $ v where id = $ k ");}} mysql_query ("update table set credit_order = $ newpage where id = $ id ");}
What algorithm is this?
Brother, believe me, after spending some time figuring out the problem,
You don't need to let the poor computer run so many queries every time .....
I have solved the problem by myself. thanks to the moderator, I want to write my own algorithms and help others.
PHP code? 123456789101112if (! Empty ($ newpage) {/*** $ arr is the inserted array, and $ page is the current file name, $ newpage is the inserted page number */foreach ($ arr as $ k = >$ v) {if ($ v >=$ newpage & $ v ......