Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-14-2005, 03:21 AM probs deleting
log2's Avatar
Skilled Talker

Posts: 80
Trades: 0
How would I go about deleting onw row from a MySQL table? here's the info:

Table: news
Setup: Id=Auto-incrementing

that's basically all the info you need... i've tried it several times but I get the same result... deletes the whole thing... any help would be apreciated
__________________

Please login or register to view this content. Registration is FREE
The future is now with 4D Realms
log2 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-14-2005, 04:03 AM
Experienced Talker

Posts: 36
Trades: 0
http://dev.mysql.com/doc/mysql/en/delete.html
tress is offline
Reply With Quote
View Public Profile
 
Old 03-14-2005, 05:25 AM
log2's Avatar
Skilled Talker

Posts: 80
Trades: 0
thanks
__________________

Please login or register to view this content. Registration is FREE
The future is now with 4D Realms
log2 is offline
Reply With Quote
View Public Profile
 
Old 03-14-2005, 05:58 AM
log2's Avatar
Skilled Talker

Posts: 80
Trades: 0
Still didn't work
__________________

Please login or register to view this content. Registration is FREE
The future is now with 4D Realms
log2 is offline
Reply With Quote
View Public Profile
 
Old 03-14-2005, 08:20 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
To delete a row is very similar to doing a select. You add a where clause to specify which rows you want to delete, usually using the primary key so that you delete one specific row:

Code:
DELETE FROM yourtable WHERE id = 7;
Will just delete that row with id 7.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-14-2005, 03:10 PM
log2's Avatar
Skilled Talker

Posts: 80
Trades: 0
But I dont have the ID, here, ill give you the code:
PHP Code:
  $qu "SELECT * FROM news ORDER BY `id` DESC LIMIT 10";
  
$res mysql_query($qu);
  if (
mysql_num_rows($res) == 0) {
    echo 
"There is no news!";
  }
  else {
    while (
$ro mysql_fetch_array($res)) {
        
$nam $ro["name"];
      
$msg $ro["news"];
      
$id $ro["id"];
      echo 
$nam ":";
      echo 
" " $msg;
      if (
$session->isAdmin()) {
      echo 
"<div align=\"right\"><a href=\"proc3.php\">Delete post</a></div>";
      }
      echo 
"<hr align=\"left\" width=75% color=blue>";
    } 
and here's proc3.php:
PHP Code:
<?
include("include/session.php");
  
$query "DELETE FROM `news` WHERE `id` = '$id' LIMIT 1";
  
mysql_query($query) or die("A mysql error has occurred: " mysql_error());
return 
$query;
  echo 
"<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=main.php\">";
?>
__________________

Please login or register to view this content. Registration is FREE
The future is now with 4D Realms
log2 is offline
Reply With Quote
View Public Profile
 
Old 03-14-2005, 04:41 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
What you need to do is when you generate the page, put the ID of the news item into the delete link:
PHP Code:
echo "<a href = \"proc3.php?ID=$id\">Delete This Post</a>"
Then on proc3.php you can retrieve the ID number from the $_GET array that PHP provides to store the values of variables in the URL:

PHP Code:
$id $_GET['id'];
mysql_query("DELETE FROM news WHERE id = $id LIMIT 1"); 
Each link has a different id number in it, and will cause that post to be deleted.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-14-2005, 05:11 PM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Trades: 1
Can I just say something?

You are using a meta refresh to relocate, which is a bad move if you wish popularity from SE's. Have you looked at the header function in php?
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 03-14-2005, 06:11 PM
log2's Avatar
Skilled Talker

Posts: 80
Trades: 0
thanks for the suggestion Gaffer, it's been noted, but It still doesn't seem to want to work Oberon, I tried the code and it processes it, but it doesn't delete, by the way, it gets the right ID i've checked that,

EDIT: nevermind, i got it working, I had to change the $_GET['id'] to $_GET['ID']... my host is very strict about capitals
__________________

Please login or register to view this content. Registration is FREE
The future is now with 4D Realms

Last edited by log2; 03-14-2005 at 06:13 PM..
log2 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to probs deleting
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.61283 seconds with 12 queries