Zahak Posted September 26, 2007 Share Posted September 26, 2007 Have some pages in the database, that i show with something like this (of course there are some code before, and some after):echo '<table width="100%">';while($row = mysql_fetch_array($result)) { $page = $row['page']; $title = $row['title']; echo '<td width="60%">' . $title . '</td>'; echo '<td width="20%"><a href="">Edit</a></td>'; echo '<td width="20%"><a href="">Delete</a></td><tr>'; }echo '</table>';Now, if I have let's say 5 pages, it'll look something like this:page1 edit deletepage2 edit deletepage3 edit deletepage4 edit deletepage5 edit deleteWhat I want is that when i press delete, the page on the same line (for example delete on first line, page1 should be deleted). How do I make this?The code for deleting in itself is not that hard (for example);mysql_query("DELETE FROM pages WHERE page='$page'");The problem is the value '$page'. How do I store that automaticly when I press the delete link?I'm probably not very good att explaining, but hopefully you get the idea :)Anyone have an idea? or perhaps any alternative method? Link to comment Share on other sites More sharing options...
denny911 Posted September 26, 2007 Share Posted September 26, 2007 Have some pages in the database, that i show with something like this (of course there are some code before, and some after):echo '<table width="100%">';while($row = mysql_fetch_array($result)) { $page = $row['page']; $title = $row['title']; echo '<td width="60%">' . $title . '</td>'; echo '<td width="20%"><a href="">Edit</a></td>'; echo '<td width="20%"><a href="">Delete</a></td><tr>'; }echo '</table>';Now, if I have let's say 5 pages, it'll look something like this:page1 edit deletepage2 edit deletepage3 edit deletepage4 edit deletepage5 edit deleteWhat I want is that when i press delete, the page on the same line (for example delete on first line, page1 should be deleted). How do I make this?The code for deleting in itself is not that hard (for example);mysql_query("DELETE FROM pages WHERE page='$page'");The problem is the value '$page'. How do I store that automaticly when I press the delete link?I'm probably not very good att explaining, but hopefully you get the idea :)Anyone have an idea? or perhaps any alternative method?here's something that might point you at the right direction:- i would make a form with some hidden fields; only visible element of that form would be its submit button, which value set to EDIT or DELETE- one of the hidden fields should have the ID value (or any other unique value in your record table). Why? Because its value will be used to uniquely identify selected record.- let's say you want to delete row 3 (or page 3, as you call it). when a user clicks the delete button (it's a form's submit button, actually, remember?), he/she will be taken to the page that deals with DELETE query and you will use there that unique value in the statement. like in yours ... WHERE page = '$page'.. so, that value of a hidden field might be from row['page']..- of course, you mustn't forget to put the appropriate action value for each of the forms!!let's resume:- create one form for EDIT and one for DELETE button (those buttons will look like standard form buttons, not simple text links)- insert appropriate hidden field(s) that will hold and (after submission) send unique value for each row- put appropriate action values for each form that will take the user where the query will be runthis was very detailed explanation, right? so i hope you'll manage to do it! Link to comment Share on other sites More sharing options...
justsomeguy Posted September 26, 2007 Share Posted September 26, 2007 You can put the value to delete in the querystring in the delete link, and the page that does the deleting gets the value and puts it in the query.echo "<a href=\"delete.php?page=" . urlencode($page) . "\">Delete</a>";The delete.php page can get the page variable from $_GET['page'], validate it, and put it into the delete statement. Link to comment Share on other sites More sharing options...
Zahak Posted September 28, 2007 Author Share Posted September 28, 2007 You can put the value to delete in the querystring in the delete link, and the page that does the deleting gets the value and puts it in the query.echo "<a href=\"delete.php?page=" . urlencode($page) . "\">Delete</a>";The delete.php page can get the page variable from $_GET['page'], validate it, and put it into the delete statement.Thanks for the answers folks. Sorry for this late answer, but I haven't got any time to test until now.Denny911: Not really the answer I was looking for, but I think it helps me to understand a bit more, and it might come handy later in my little project :)justsomeguy: Hehe, really simple, but yet very effective. I use that method in some other parts of the site, don't know why I didn't think of that here. Thanks for the help thoe, it's not usual to know as much as you do and yet keep it simple enough for us mortals :)Thanks again, both of you!(btw, it works now ) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.