NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Deleting from mysql, ids go the same.

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-19-2006, 10:05 AM THREAD STARTER               #1 (permalink)
Senior Member
 
killaklown's Avatar
Join Date: Oct 2003
Posts: 3,472
killaklown is a splendid one to beholdkillaklown is a splendid one to beholdkillaklown is a splendid one to beholdkillaklown is a splendid one to beholdkillaklown is a splendid one to beholdkillaklown is a splendid one to beholdkillaklown is a splendid one to beholdkillaklown is a splendid one to behold
 



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.
Last edited by killaklown; 08-19-2006 at 10:12 AM.
killaklown is offline  
Old 08-19-2006, 10:07 AM   #2 (permalink)
OK
NamePros Regular
Join Date: Nov 2005
Posts: 460
OK is just really niceOK is just really niceOK is just really niceOK is just really nice
 



PHP Code:
    while ($row mysql_fetch_array($rs))
    {
        
$title $row["title"];
        
$url $row["url"];
        
$id $row["id"];
        
$category $row["category"];
????: NamePros.com http://www.namepros.com/showthread.php?t=229388
        
$description $row["description"];
        
if(isset(
$_GET["delete"])) {
    
$sid $_GET["delete"];
    
mysql_query("DELETE FROM tutorials WHERE id='$sid' 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>");
????: NamePros.com http://www.namepros.com/showthread.php?t=229388
    } 
Try that...

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
OK is offline  
Old 08-19-2006, 10:10 AM   #3 (permalink)
NamePros Regular
 
baxter's Avatar
Join Date: Apr 2006
Posts: 363
baxter is just really nicebaxter is just really nicebaxter is just really nicebaxter is just really nice
 


Ethan Allen Fund Save The Children
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:
while ($row mysql_fetch_array($rs))
{
    
$title $row["title"];
    
$url $row["url"];
    
$id $row["id"];
    
$category $row["category"];
????: NamePros.com http://www.namepros.com/showthread.php?t=229388
????: NamePros.com http://www.namepros.com/showthread.php?t=229388
    
$description $row["description"];
        
if(
intval($_GET['delete']) == $id) {
    
mysql_query("DELETE FROM tutorials WHERE id='$id' LIMIT 1");
    continue;
}
    
    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: missed closing bracket in intval
baxter is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 06:16 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger