jd2007 Posted July 19, 2007 Share Posted July 19, 2007 how do i delete a full row in mysql ? Link to comment https://forums.phpfreaks.com/topic/60782-how-do-i-delete-a-full-row-in-mysql/ Share on other sites More sharing options...
chigley Posted July 19, 2007 Share Posted July 19, 2007 DELETE FROM table WHERE x = 'y' Link to comment https://forums.phpfreaks.com/topic/60782-how-do-i-delete-a-full-row-in-mysql/#findComment-302355 Share on other sites More sharing options...
thedarkwinter Posted July 19, 2007 Share Posted July 19, 2007 Every row should have a an ID number for indexing, preferably a auto_increment field. Therefore, the command to delete a row is DELETE FROM mytable WHERE rowid=xxx; Link to comment https://forums.phpfreaks.com/topic/60782-how-do-i-delete-a-full-row-in-mysql/#findComment-302357 Share on other sites More sharing options...
dbo Posted July 19, 2007 Share Posted July 19, 2007 Well it depends on the structure of the table you're trying to delete from, but the general syntax is: DELETE FROM <tablename> WHERE <field> = <value>; For example: This is my table structure.... COLOR -------- ID Name Description This is some sample data 1, Red, A red color 2, Green, A green color DELETE FROM `COLOR` WHERE `ID` = 2; No more row 2. I suggest always deleting from tables by using the primary key... when possible. I'd suggest against saying: DELETE FROM `COLOR` WHERE `Name` = 'GREEN'; Link to comment https://forums.phpfreaks.com/topic/60782-how-do-i-delete-a-full-row-in-mysql/#findComment-302359 Share on other sites More sharing options...
jd2007 Posted July 19, 2007 Author Share Posted July 19, 2007 what happens is after its deleted the id for other's doesnt change .... how do i update this id ? Link to comment https://forums.phpfreaks.com/topic/60782-how-do-i-delete-a-full-row-in-mysql/#findComment-302366 Share on other sites More sharing options...
dbo Posted July 19, 2007 Share Posted July 19, 2007 They won't change. Also primary keys are not updatable. Why would you want them to? Link to comment https://forums.phpfreaks.com/topic/60782-how-do-i-delete-a-full-row-in-mysql/#findComment-302373 Share on other sites More sharing options...
jd2007 Posted July 19, 2007 Author Share Posted July 19, 2007 is there a way to change all ids ? Link to comment https://forums.phpfreaks.com/topic/60782-how-do-i-delete-a-full-row-in-mysql/#findComment-302380 Share on other sites More sharing options...
thedarkwinter Posted July 19, 2007 Share Posted July 19, 2007 you really don't want to do that, ever ??? Link to comment https://forums.phpfreaks.com/topic/60782-how-do-i-delete-a-full-row-in-mysql/#findComment-302388 Share on other sites More sharing options...
dbo Posted July 19, 2007 Share Posted July 19, 2007 If you're just wanting the numbers to be in order.... consider this. $result = mysql_query("SELECT `ID`, `Name` FROM `COLOR`"); $rows = mysql_num_rows($result); echo "<table><tr>"; echo "<th>Fake ID</th>"; echo "<th>Real ID</th>"; echo "<th>Name</th>"; echo "</tr>"; for($i = 0; $i < $rows; ++$i ) { $row = mysql_fetch_row($result); echo "<tr>"; echo "<td>" . $i . "</td>"; echo "<td>" . $row[0] . "</td>"; echo "<td>" . $row[1] . "</td>"; echo "</tr>"; } echo "</table>"; So then you get a "fake id" that is ordered how you want (i think). But behind the scenes you have the real ids that aren't being updated... and the user doesn't have to see them (and probably shouldnt). Link to comment https://forums.phpfreaks.com/topic/60782-how-do-i-delete-a-full-row-in-mysql/#findComment-302399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.