doddsey_65 Posted November 20, 2009 Share Posted November 20, 2009 I currently have a user managment system im working on. What i want is to have a hyperlink next to the rows that are pulled(see code below). with this button i can delete the respective row from the db therefore deleting the user. Here is the code i am using to display their details: $sql = "SELECT name, email, date FROM users"; $res = mysql_query($sql, $db); while($row = mysql_fetch_array($res, MYSQL_ASSOC)) { echo $row['name'] . ": " . $row['email'] . " -- " . $row['date']; echo "<br />"; } I know how to delete records, what i dont know how to do is to delete the record I want ie. the one next to the delete link if you know what i mean. Quote Link to comment https://forums.phpfreaks.com/topic/182246-solved-delete-table-row-hyperlink/ Share on other sites More sharing options...
Ken2k7 Posted November 20, 2009 Share Posted November 20, 2009 You can have the button or the link next to it contain a unique ID corresponding to the row entry in the DB you want to remove. Quote Link to comment https://forums.phpfreaks.com/topic/182246-solved-delete-table-row-hyperlink/#findComment-961670 Share on other sites More sharing options...
doddsey_65 Posted November 20, 2009 Author Share Posted November 20, 2009 You can have the button or the link next to it contain a unique ID corresponding to the row entry in the DB you want to remove. how would i go about doing that? Quote Link to comment https://forums.phpfreaks.com/topic/182246-solved-delete-table-row-hyperlink/#findComment-961671 Share on other sites More sharing options...
Ken2k7 Posted November 20, 2009 Share Posted November 20, 2009 I presume you have a unique ID column for the table users right? Quote Link to comment https://forums.phpfreaks.com/topic/182246-solved-delete-table-row-hyperlink/#findComment-961673 Share on other sites More sharing options...
doddsey_65 Posted November 20, 2009 Author Share Posted November 20, 2009 I presume you have a unique ID column for the table users right? yes, but how would i get the hyperlink to know its the user next to it that i want it to delete Eg. User: Tom [delete] User: Dick [delete] User: Harry[delete] How would i delete tom with the code i am using to display them Quote Link to comment https://forums.phpfreaks.com/topic/182246-solved-delete-table-row-hyperlink/#findComment-961677 Share on other sites More sharing options...
emopoops Posted November 20, 2009 Share Posted November 20, 2009 DELETE FROM table WHERE url = '$badurl' Quote Link to comment https://forums.phpfreaks.com/topic/182246-solved-delete-table-row-hyperlink/#findComment-961702 Share on other sites More sharing options...
doddsey_65 Posted November 20, 2009 Author Share Posted November 20, 2009 DELETE FROM table WHERE url = '$badurl' sorry mate but that made no sense lol Quote Link to comment https://forums.phpfreaks.com/topic/182246-solved-delete-table-row-hyperlink/#findComment-961706 Share on other sites More sharing options...
emopoops Posted November 20, 2009 Share Posted November 20, 2009 well hon im just trying to help u say u want to selet a row. but if u got nothing to go off of you cant delete it. u didnt state what u were going off of to delete the row.. so i assumed the url was it. makes perfect sense. Quote Link to comment https://forums.phpfreaks.com/topic/182246-solved-delete-table-row-hyperlink/#findComment-961708 Share on other sites More sharing options...
ngreenwood6 Posted November 20, 2009 Share Posted November 20, 2009 here is an example: if($_GET['method']=='delete' && $_GET['id']){ $query = "DELETE FROM table WHERE id='".$_GET['id']."'"; //delete the entry from the database mysql_query($query); //make the queyr } $sql = "SELECT name, email, date FROM users"; $res = mysql_query($sql, $db); while($row = mysql_fetch_array($res, MYSQL_ASSOC)) { echo $row['name'] . ": " . $row['email'] . " -- " . $row['date']; echo '<a href="thecurrentpage.php?method=delete&id='.$row['id'].'">Delete</a>'; echo "<br />"; } All you are doing is creating a link with a $_GET post(in a sense). Then if that is set you are deleting it and if not it doesnt delete it. Obviously in this example you would have to have unique id in the database and you would change the href to the page that you are currently on. Quote Link to comment https://forums.phpfreaks.com/topic/182246-solved-delete-table-row-hyperlink/#findComment-961713 Share on other sites More sharing options...
emopoops Posted November 20, 2009 Share Posted November 20, 2009 there you go. or you can do it with a form post. Quote Link to comment https://forums.phpfreaks.com/topic/182246-solved-delete-table-row-hyperlink/#findComment-961717 Share on other sites More sharing options...
ngreenwood6 Posted November 20, 2009 Share Posted November 20, 2009 @emopoops that makes no sense that he would delete a user by the url. you should never delete a user by a name or age or some other value that can be in another users field. There should be a unique value in the database that identifies the user. Hence the use of an incrementing id. Then you can delete it by using its UNIQUE id. Almost every table I make in the database has a unique id. Quote Link to comment https://forums.phpfreaks.com/topic/182246-solved-delete-table-row-hyperlink/#findComment-961718 Share on other sites More sharing options...
emopoops Posted November 20, 2009 Share Posted November 20, 2009 at ngreenwood. i was just using url as an example. ebcause the lard didnt even specifu what his thing was all the post was about was the url this and url that. i fiugred it was the dang id name ok. Quote Link to comment https://forums.phpfreaks.com/topic/182246-solved-delete-table-row-hyperlink/#findComment-961724 Share on other sites More sharing options...
doddsey_65 Posted November 20, 2009 Author Share Posted November 20, 2009 @emopoops that makes no sense that he would delete a user by the url. you should never delete a user by a name or age or some other value that can be in another users field. There should be a unique value in the database that identifies the user. Hence the use of an incrementing id. Then you can delete it by using its UNIQUE id. Almost every table I make in the database has a unique id. same here, i have an ai on an id table. cheers for the help people. I did think halfway through however why dont i just gointo the database and delete them, but im going to use this way anyway cos my db loads too slowly. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/182246-solved-delete-table-row-hyperlink/#findComment-961725 Share on other sites More sharing options...
emopoops Posted November 20, 2009 Share Posted November 20, 2009 yeah dont gan gup on me i was only tryng to concentate what the lard was trying to state. Quote Link to comment https://forums.phpfreaks.com/topic/182246-solved-delete-table-row-hyperlink/#findComment-961728 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.