[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 08-19-2006, 09:05 AM   #1 (permalink)
Senior Member
 
Join Date: Oct 2003
Location: Winnipeg, Canada
Posts: 3,472
5.31 NP$ (Donate)

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 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?

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 09:12 AM.
killaklown is offline  
Old 08-19-2006, 09:07 AM   #2 (permalink)
OK
NamePros Regular
 
Join Date: Nov 2005
Posts: 458
227.55 NP$ (Donate)

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"];
        
$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>");
    }
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");
OK is offline  
Old 08-19-2006, 09:10 AM   #3 (permalink)
NamePros Regular
 
baxter's Avatar
 
Join Date: Apr 2006
Posts: 289
1,990.00 NP$ (Donate)

baxter is a jewel in the roughbaxter is a jewel in the roughbaxter is a jewel in the rough

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"];
    
$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 :P
baxter is offline  
Closed Thread


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 02:11 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85