PDA

View Full Version : subtract a num from table



insanemonkey
12-11-2007, 10:37 PM
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..


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

boogyman
12-12-2007, 02:03 PM
provided you assigned $number correction to $delnum try


$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.


if( mysql_query("DELETE FROM forum WHERE postid='". $delnum. "'") )
{
echo mysql_query("SELECT COUNT(postid) FROM forum");
}

insanemonkey
12-15-2007, 10:51 AM
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




<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