Hey there
I'm in a bit of trouble here, seeing as I don't know how to loop through columns and update their values.
I am making a small script to delete values from a table. Every entry in the table has an "ID" and an "URL" tag. The problem when I delete an entry, though, is that the ID's do not update, and the result is this:
http://img443.imageshack.us/img443/3518/examplej.jpg
So I have created a while loop, which should update the ID-values (decrement all the values of ID by 1 after the deleted entry for every row).
It doesn't do that, however. And I'm not sure what I'm doing wrong.
Here is the code:
<?
$id = $_POST['acceptid'];
$con = mysql_connect("localhost","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("urllist", $con);
$result = mysql_query("SELECT * FROM urllist WHERE ID='$id'");
$row = mysql_fetch_array($result);
$voreslink = $row['url'];
mysql_query("INSERT into linkpool (url) VALUES('$voreslink')");
mysql_query("DELETE FROM urllist WHERE ID='$id'");
(int)$id++;
while ($id = $row)
{
(int)$newID = (int)$id-1;
mysql_query("UPDATE urllist SET ID = '$newID' WHERE ID = '$ID'");
(int)$id++;
}
?>
I know the code is a bit long, but it's just in case you need to know the rest.
The $id is sent from another PHP-page, and contains the ID-number to be deleted. 1,2,3 etc.
Thanks in advice