mysql mass decrement ID field
Posted: Tue Apr 01, 2008 2:40 pm
here is a snippet of code i am building, the goal will be to delete an entry from the database then decrement the remaining ID fields by one to fill the gap, that way when a new entry is added its added with the proper value
the delete query works so i commented it out for debugging purposes
the UPDATE query when passed values echos out to
Code: Select all
<?php
$mysqli = new mysqli("localhost", "root", "****" "htf");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
else {
$sql = "DELETE FROM ".$_GET['type']." WHERE id=".$_GET["id"];
echo $sql;
//mysqli_query($mysqli, $sql);
echo "File Removed<br>";
//for ($x = $_GET['id']; $x <= $_GET['highest']-1; $x++) {
//$y=$x+1;
$sql = "UPDATE {$_GET['type']} SET id= id - 1 WHERE id > {$_GET['id']}";
echo $sql."<br>";
mysqli_query($mysqli, $sql) or die('failed');
//}
mysqli_close($mysqli);
}
//echo "<meta http-equiv=\"refresh\" content=\"0; URL=\"./manage.php\">";
?>
the UPDATE query when passed values echos out to
Code: Select all
UPDATE Other SET id= id - 1 WHERE id > 3Code: Select all
but dies
any suggestions?