How to delete a particular row in a sql table? [duplicate]
Possible Duplicate:
How to get the row number of ID of a sql table?
Say: i ne开发者_StackOverflow中文版ed to delete the 5th row, or the 6th or the 20th...???
I don't think this is possible in MySQL. The problem you have is the row number is subjective based on how the data is ordered. If you order your data by column 1 in ascending order and then you order by column 1 by descending order, which is row 1?
Preferably your tables should have primary key id fields in which you can specify them to delete.
DELETE FROM *table* WHERE id = *id*
You can use LIMIT
in a DELETE
request if you are using MySQL ^^
EDIT: Sorry it's not enough
The MySQL-specific LIMIT row_count option to DELETE tells the server the maximum number of rows to be deleted before control is returned to the client. This can be used to ensure that a given DELETE statement does not take too much time. You can simply repeat the DELETE statement until the number of affected rows is less than the LIMIT value.
$lcv = 0;
$row_to_delete = x;
$result = mysql_query("SELECT * FROM table");
while($row = mysql_fetch_array($result){
if($lcv == $row_to_delete){
mysql_query("DELETE");
}
$lcv++;
}
精彩评论