Results 1 to 3 of 3

Thread: subtract a num from table

  1. #1
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default subtract a num from table

    ok I am making a delete page for my forum and i got everything completed, it works fine and everything but this is my code..

    Code:
    include "connect.php";
    
    $delnum = $number;
    
    mysql_query("DELETE FROM forum WHERE postid='$delnum'") 
    or die(mysql_error());
    but i use this for my forum and i have a seperate table called replies and it adds +1 everytime there is a reply but i want to know how i can make is subtract one everytime i delete a reply that it will subtract one

    I dont know if this would be under php or mysql, sorry if i was wrong.

    example:
    10 replies delete one goes to 9 replies. but i delete one it still says 10 replies but there is only 9
    Hey new design new look, goto xudas for personal webdsign help.. (:

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    provided you assigned $number correction to $delnum try
    PHP Code:
    $delnum $number;

    mysql_query("DELETE FROM forum WHERE postid='"$delnum"'") or die(mysql_error()); 
    and if you want to find out if it worked you can do.
    PHP Code:
    if( mysql_query("DELETE FROM forum WHERE postid='"$delnum"'") )
    {
          echo 
    mysql_query("SELECT COUNT(postid) FROM forum");


  3. #3
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    ok heres a code i am trying to figure out,, its a modified version.


    Hi everyone, I can seem to figure this out and why its not working, please help.

    what I am trying to do is make a delete page for my forum which will delete the post id then i want it to update the parentid and to subtract 1 from number of replies.. heres what I am trying to do..

    the delete button a post would look like this..
    forums/delete.php?delnum=105&id=104



    Code:
    <html> 
    <head> 
    
    </head> 
    
    <body onLoad="history.go(-1)"> 
    <body bgcolor="#000000"> 
    
    </body> 
    
    </html> 
    
    <?php 
      
    $delnum = $delnum; //post number 
    $sid = - 1; //subtract 1 from parentid or replies 
    $id = $id; 
     ?> 
    
    <?php 
    include "connect.php"; 
    
    
    mysql_query("DELETE FROM forum WHERE postid='$delnum'")  
    or die(mysql_error());  //delete the post 
    
    
    mysql_query("UPDATE forum SET numreplies='$sid' WHERE postid='$id'")  
    or die(mysql_error()); //update number of replies by -1 where post id is 
    
    ?>
    please help me out...
    after it completes i want it to go back a page... thats why I have onload in there..
    this wont even delete the post.. please help
    Hey new design new look, goto xudas for personal webdsign help.. (:

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •