| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: Oct 2003
Posts: 3,472
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Deleting from mysql, ids go the same. When i click on Delete, it will delete the row from the mysql, but it will change all the ids to the same (as the one i deleted) and the row i deleted still shows up. I would need to refresh the page to change the ids back to their original ones and to have the row i deleted to dissapear. How can i do this without pressing the refresh button? ????: NamePros.com http://www.namepros.com/programming/229388-deleting-from-mysql-ids-go-same.html The code is: Code: while ($row = mysql_fetch_array($rs))
{
$title = $row["title"];
$url = $row["url"];
$id = $row["id"];
$category = $row["category"];
$description = $row["description"];
if(isset($_GET["delete"])) {
$id = $_GET["delete"];
mysql_query("DELETE FROM tutorials WHERE id='$id' LIMIT 1");
}
echo("<tr><td>$id</td><td>$title</td><td>$category</td><td>$description</td><td>Edit | <a href=\"tutorials.php?delete=$id\">Delete</a></td></tr>");
} Edit: i just fixed it so they dont all change to the same id (changed the $id in the isset to $tid) But how can i automaticaly refresh it? Edit: i got it to work.
__________________ hostvouchers - Coupons and Reviews for the top web hosts! (shared, reseller, vps, servers, adult, offshore, proxy)
Last edited by killaklown; 08-19-2006 at 10:12 AM.
|
| |
| | #2 (permalink) |
| NamePros Regular Join Date: Nov 2005
Posts: 460
![]() ![]() ![]() ![]() | PHP Code: You overwrite $id and therefore remains constant. Try to change to $sid or some other variable not in use. quote : Edit: i just fixed it so they dont all change to the same id (changed the $id in the isset to $tid) But how can i automaticaly refresh it? [[yea im lazy ]]use the header function. header("Location: http://www.example.com/pageyouwanttogotto");
__________________ Oleg |
| |
| | #3 (permalink) |
| NamePros Regular Join Date: Apr 2006
Posts: 363
![]() ![]() ![]() ![]() | I think this will be what your looking for: just changed it to make sure the id == the deleted row id. and continued the loop if it did so it doesn't print it out after deleting it. Hope that helps PHP Code: |
| |