Save a bunch of files, path into the database, to page 123456 ... Number naming, now want to insert a file in it, how should the algorithm be written?
My idea is to pull the path from the data, add a file name larger than the number of pages that need to be inserted, and then update the database file name in bulk. But now run after the database does not respond, ask me this idea right??
The source code is as follows
$newpage//New Page $res = mysql_query ("Select id,page from table by page ASC"), while ($arr =mysql_fetch_row ($res)) {$arr 2[$arr [ 0]]= $arr [1];} $count =count ($arr 2) +1;for ($i = $newpage; $i < $count-$newpage; $i + +) {$arr 3[$i]= $arr 2[$i]+1;} foreach ($arr 3 as $k = + $v) {$q = mysql_query ("Update table Set page = case ID if $k then $v");}
Reply to discussion (solution)
$q = mysql_query ("Update table Set page = case ID if $k then $v");
Then what is it?
Case when ... then .... The sentence pattern
Bulk upload
Does anyone know??
1. Not very clear what you mean, give a table structure and a simple example,
2. It doesn't seem so troublesome, it should be simple SQL to achieve the effect of your current code
3. If the "post-run database does not respond", it should be wrong to at least display the error message
I found that my algorithm did have problems, and some cases were not taken into account.
I am now the case, the file name is named with a series of numbers, such as 1, 2, 3, 4, 5, the path into the database, now want to insert the file 5 in front of 2, the original 2, 3, 4 filenames will be added 1, do you have other good ideas or examples of the great God?? Think of a day or not, thank you.
Update ... set num=num+1 where num between 2 and 5-1
Update ... set num=2 where num=5
Try it, or not.
Is that you didn't describe the requirements clearly.
Solve their own problems, thank you moderator, now the algorithm to write their own, hoping to help other people.
if (!empty ($newpage)) {/*** $arr is the inserted array, $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 kind of algorithm is this?
Brother, believe me, take the time to get the problem straight.
You don't have to let the poor computer run so many queries every time .....
Solve their own problems, thank you moderator, now the algorithm to write their own, hoping to help other people.
PHP code?123456789101112if (!empty ($newpage)) {/*** $arr is the inserted array, $page is the current file name, $newpage is the inserted page number */foreach ($arr as $k + = $v ) {if ($v >= $newpage && $v ...