Goon Posted July 9, 2008 Share Posted July 9, 2008 When you retrieve data from a mysql table is it possible to have an edit option next to each of the returned results? I would like to have the option to update or delete results returned if possible. Quote Link to comment https://forums.phpfreaks.com/topic/113958-editupdate-query-results/ Share on other sites More sharing options...
KevinM1 Posted July 9, 2008 Share Posted July 9, 2008 When you retrieve data from a mysql table is it possible to have an edit option next to each of the returned results? I would like to have the option to update or delete results returned if possible. Yes, it's possible. The most simple way to do it is to have an 'Edit/Delete' input button associated with each result. How this association is formed depends on how the items you want to modify are structured. Once this button is clicked, it brings the user to an editing page which puts the data in form inputs that the user can modify. Here there should be two more buttons: 'Save Modifications' and 'Delete Record'. When 'Save Modifications' is clicked, the data in the form fields is updated in the DB. When 'Delete Record' is pressed, the record is deleted from the DB. There are other ways to get at the records...I've used checkboxes to specify multiple records to be edited/deleted. It's not much harder to implement, once you get the basics down. Can you work from here, or do you need to see some code? Quote Link to comment https://forums.phpfreaks.com/topic/113958-editupdate-query-results/#findComment-585664 Share on other sites More sharing options...
Third_Degree Posted July 9, 2008 Share Posted July 9, 2008 of course <?php if ( empty( $_GET["action"] ) ) { $results = mysql_query( "SELECT * FROM table" ); while ( $result = mysql_fetch_object( $results ) ) { print $result->body . "<br />Edit Text:<br /> <form action='this.php?action=edit&id=" . $result->id . "' method='post'> <textarea name='newbody' rows='10' cols='10'>" . $result->body . "</textarea><br /> <input type='submit' value='Edit' /></form> <a href='this.php?action=del&id=" . $result->id . "'>Delete</a>"; } die( ); } switch ( $_GET["action"] ) { case "edit": mysql_query( "UPDATE `table` SET `body`='" . mysql_real_escape_string( $_POST["newbody"] ) . "' WHERE `id`='" . settype( $_GET["id"], "int" ) . "'" ); break; case "del": mysql_query( "DELETE FROM `table` WHERE `id`='" . settype( $_GET["id"], "int" ) . "'" ); break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/113958-editupdate-query-results/#findComment-585669 Share on other sites More sharing options...
Goon Posted July 9, 2008 Author Share Posted July 9, 2008 Guys, I'll really appreciate your help on this. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/113958-editupdate-query-results/#findComment-585673 Share on other sites More sharing options...
dannyb785 Posted July 9, 2008 Share Posted July 9, 2008 Guys, I'll really appreciate your help on this. Thanks but ... they have helped... what more do you need? Quote Link to comment https://forums.phpfreaks.com/topic/113958-editupdate-query-results/#findComment-585675 Share on other sites More sharing options...
Goon Posted July 9, 2008 Author Share Posted July 9, 2008 No, that's fine, just saying thanks Quote Link to comment https://forums.phpfreaks.com/topic/113958-editupdate-query-results/#findComment-585684 Share on other sites More sharing options...
dannyb785 Posted July 10, 2008 Share Posted July 10, 2008 Oh, I guess it would've been more clear if you said "I appreciate" When you said "I'll appreciate" it made it sounds like they havent helped you yet Quote Link to comment https://forums.phpfreaks.com/topic/113958-editupdate-query-results/#findComment-586064 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.