SirChick Posted October 16, 2007 Share Posted October 16, 2007 Say i have three rows: row1 row2 row3 How do i make a mysql query to delete a specific row out of the 3 only? So say i wanted to delete row2 from the 3.. ? Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/ Share on other sites More sharing options...
thedarkwinter Posted October 16, 2007 Share Posted October 16, 2007 every row should have a specific index/id - right? so the query would be DELETE FROM mytable WHERE rowid=2; cheers, rdw Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-370790 Share on other sites More sharing options...
hostfreak Posted October 16, 2007 Share Posted October 16, 2007 Edit: beat to it Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-370792 Share on other sites More sharing options...
darkfreaks Posted October 16, 2007 Share Posted October 16, 2007 nvm Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-370794 Share on other sites More sharing options...
SirChick Posted October 16, 2007 Author Share Posted October 16, 2007 i cant do rowid=2 cos it could be any id number... =/ Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-370798 Share on other sites More sharing options...
kernelgpf Posted October 16, 2007 Share Posted October 16, 2007 What is your ultimate goal? Why are you deleting one out of every three? Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-370815 Share on other sites More sharing options...
SirChick Posted October 16, 2007 Author Share Posted October 16, 2007 no an example would be "if delete message 2 is yes then "mysql code here" But message 2 could be any ID number out of thousands... so i find the messages which are the user's inbox messages and then out of them itll pick the second message ... the max inbox is 3 messages so they have to delete one of the 3 in order to receive a 4th message. etc Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-370824 Share on other sites More sharing options...
kernelgpf Posted October 16, 2007 Share Posted October 16, 2007 Oh, I think I understand. In their inbox when they view a message, it uses the auto incremented ID, correct? Just pass it along in the URL via GET, and have a button saying "delete", and use something like this: <?php $messageID=$_GET['messageID']; mysql_query("delete from messages where messageID='$messageID'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-370827 Share on other sites More sharing options...
SirChick Posted October 16, 2007 Author Share Posted October 16, 2007 umm i dont know if i understand that... lets pretend we have 3 rows: row 1 = ID is 2424 row 2 = ID is 2342424 row 3 = ID is 2 Now the mysql has to delete position of row 2 cos it will always and only ever have 3 to choose from and their sorted via newest at the top and oldest to the bottom.. Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-370830 Share on other sites More sharing options...
igor berger Posted October 16, 2007 Share Posted October 16, 2007 If you always need to delete row number 2 create a new column and call it row_number then put 1, 2, 3 as values Then you can run a MySql coomand to delete row_number=2 If that is what you trying to achive. Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-370852 Share on other sites More sharing options...
igor berger Posted October 16, 2007 Share Posted October 16, 2007 Sorry actually that is bad logic. Because if you have 3 rows and you always put the data in them and you delete a row how you going to use the database template? So you will need to either update the information in a row with empty value and not delete it, or you will need to create the row again next time and assign row_number=2 to it. Updating with empty value is the best choice because the template is static. Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-370855 Share on other sites More sharing options...
SirChick Posted October 16, 2007 Author Share Posted October 16, 2007 I don't see the point in updating it to a blank record... basically say theres 3 rows.. i need a way for those 3 rows that are found from a query to be put into an array so i can pick which row of the 3 found i want to delete.. it can be any one of them 3 rows that can be deleted and their ID's could be of any number. Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-370869 Share on other sites More sharing options...
igor berger Posted October 16, 2007 Share Posted October 16, 2007 But you need to assign some sort of index to the rows in order to delete them or to update with empty field value. Or you need to search for spefic value to identify which row you need to modify. For example variable_1 variable_2 variable_3 row 1 =a1 =a2 =a3 row 2 =b1 =b2 =b3 row 3 =c1 Now we give a MYSql command to delete or update row if variable_2=a2 or what ever specific value your chose. There has to be an identifiable key, or if the database always has 3 rows only, it is a static template and you just feel the values in row 2 with empty fields accept the key of the row which you need to asign to a variable called row_id Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-370881 Share on other sites More sharing options...
SirChick Posted October 16, 2007 Author Share Posted October 16, 2007 seeing as there are only 3 rows cant i "fetch row" and then delete the row it fetches? Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-370883 Share on other sites More sharing options...
igor berger Posted October 16, 2007 Share Posted October 16, 2007 And how you going to fetch a row if you do not have an assigned identifiable field value? Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-370905 Share on other sites More sharing options...
SirChick Posted October 17, 2007 Author Share Posted October 17, 2007 well fetch row always gets the first row regardless of what the row is .. then if u do fetch row again itll then be on the 2nd row etc ... or no? Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-371518 Share on other sites More sharing options...
envexlabs Posted October 17, 2007 Share Posted October 17, 2007 Oh, I think I understand. In their inbox when they view a message, it uses the auto incremented ID, correct? Just pass it along in the URL via GET, and have a button saying "delete", and use something like this: <?php $messageID=$_GET['messageID']; mysql_query("delete from messages where messageID='$messageID'"); ?> That is right. You create your query which grabs the first 3 rows, these are the newest in the database. $select = mysql_query('SELECT * FROM messages LIMIT 3'); Assuming that the ID field is the first field, you render out a link with each row. while($message = mysql_fetch_row($select)){ echo 'Name' . '<a href="index.php?delete=true&id=' . $message[0] . '">Delete?</a>' } That will render out a link, with a dynamic delete link, for each row. Quote Link to comment https://forums.phpfreaks.com/topic/73502-delete-specific-row-out-of-3/#findComment-371532 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.