Może działa ale nie działa pod względem odejmowania w liczniku komentarzy o 1 bo o to mi chodziło. Mam tabele articles i comments, w articles jest pole comments_counter w którym jest zapisywana liczba komentarzy i przy usuwaniu komentarza chcę aby w liczniku sie zmniejszyla o 1 liczba komentrzy.
To jest funkcja dodawania komentarzy bo na niej z deka sie wzorowalem ale mi nie wyszło:
<?php
function add_comment($comment, $id){
global $DBhost,$DBuser, $DBpass; include (\"themes/template/header.php\");
$title = \"\"._COMMENT_OK.\"\";
open_table($title);
$sql = \"INSERT INTO comments (aid, parent, name, text) VALUES ('$comment[aid]','$comment[parent]' ,'$comment[name]', '$comment[text]')\";
$sql1 = \"UPDATE articles SET comment_counter=comment_counter+1 WHERE id=$comment[aid
]\";
mysql_query($sql)or
die(\"ERROR, try it again...\".mysql_error()); mysql_query($sql1)or
die(\"ERROR, try it again...\".mysql_error()); echo \"<center><span class=\"text\"><a href=\"index.php?link=articles.php&op=read&id=\".$id.\"\">\"._BACK_TO_ARTICLE.\"</a></span></center>\"; close_table();
}
?>
a ta funkcja kasowania komentarzy i updatowania counter_comments nie działa mi choć błąd mi się juz nie pokazuje:
<?php
function delete_comments($id){
mysql_query(\"DELETE FROM comments WHERE id=$id\"); $sql = \"UPDATE articles SET comment_counter=comment_counter-1 WHERE id='{$comment[id]}'\";
$sql1 = \"SELECT * FROM `comments` WHERE `id`=$id\";
echo \"<link rel=\"stylesheet\" href=\"styles.css\" type=\"text/css\">\"; echo \"<br><span class=\"text\"><center>\"._COMDELETE.\".<br></center></span>\"; }
?>
Może to coś pomorze wam przy moim problemie, ale będę myślał i próbował dalej, jak mi wyjdzie to wam napisze.