X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=blobdiff_plain;f=db.php;h=428c1bf007bb42f85b5551e0633695985dd2ce0d;hp=2dccfbcef63bafc5699c14e10f8c4e4a93a1f28b;hb=HEAD;hpb=90448b433585ec63832845ae50deb01b4124adc0 diff --git a/db.php b/db.php index 2dccfbc..428c1bf 100644 --- a/db.php +++ b/db.php @@ -276,7 +276,7 @@ function db_get_value($table, $column, $where = '') { $result = db_send_get($table, $column, $where, $args); $value = mysqli_fetch_row($result); - if($value !== false) { + if($value !== NULL) { $value = $value[0]; } @@ -466,10 +466,22 @@ function db_reposition_respace($table, $field, $where = '') { return; } $inc = floor(DB_ORD_MAX / ($c + 1)); - $cur = $inc; - foreach($ids as $id) { - db_update($table, $field, $cur, 'where id=%i', $id); - $cur += $inc; + $ord = $inc; + $count = count($ids); + for ($i = 0; $i < $count; $i += 1000) { + $values = []; + $j_max = min($count, $i + 1000); + for ($j = $i; $j < $j_max; ++$j) { + $id = $ids[$j]; + $values[] = "($id,$ord)"; + $ord += $inc; + } + $sql = + "insert into $table (id,$field) values " + . implode(',', $values) + . " on duplicate key update $field=VALUES($field)" + ; + db_send_query($sql); } }