Shaun13 Posted May 13, 2007 Share Posted May 13, 2007 Here is a snipet from a script I have. elseif($action == "reply") { $topicid=$_POST['topicid']; $sql8="SELECT MAX(answerid) AS Maxanswerid FROM $tablereplies"; $result8=mysql_query($sql8); $rows8=mysql_fetch_array($result8); if ($rows8) { $Maxid = $rows8['Maxanswerid']+1; } else { $Maxid = 1; } $myusername=$_SESSION['myusername']; $mydisplayname=$displayname; $content=$_POST['content']; $author=$myusername; $authordisplay=$displayname; $datetime=date("m/d/y H:i:s"); // create date and time $sql9="INSERT INTO $tablereplies(questionid, answerid, author, authordisplay, content, datetime)VALUES('$topicid', '$Maxid', '$author', '$authordisplay', '$content', '$datetime')"; $result9=mysql_query($sql9); if($result9) { $topicid2=$_POST['topicid']; $sql14="SELECT MAX(answerid) AS Maxreplies FROM $tablereplies WHERE questionid='$topicid2'"; $result14=mysql_query($sql14); $rows14=mysql_fetch_array($result14); echo "<br><br>Successful<BR>"; echo "<a href='index.php?viewtopic=".$topicid."'>View your answer</a>"; if ($rows8) { $Maxreplies = $rows14['Maxreplies']+1; } else { $Maxreplies = 1; } $sql10="UPDATE $tableposts SET posts='$Maxreplies' WHERE id='$topicid'"; $result10=mysql_query($sql10); } else { echo "ERROR"; } } This is called when a user submits an answer to a topic. What I want it to do is update the number of replies (posts) in a topic to the MAX(answerid) for a topic (topicid) and then add 1 to that. What it is doing is adding 1 to the MAX(answerid) for ALL topics. SO if a topic's, say id 1, MAX(answerid) is 2 and topic 2's MAX(answerid) is 7, when someone adds a reply to topic 1, the number of replies (posts) is updated to 8, not 3. I hope this makes sense. Any help is appreciated. ~Shaun Quote Link to comment https://forums.phpfreaks.com/topic/51240-little-help/ Share on other sites More sharing options...
Shaun13 Posted May 13, 2007 Author Share Posted May 13, 2007 Does this make sense to anyone? ~Shaun Quote Link to comment https://forums.phpfreaks.com/topic/51240-little-help/#findComment-252416 Share on other sites More sharing options...
Dragen Posted May 13, 2007 Share Posted May 13, 2007 if I understand you correctly you're wanting seperate post counts for each topic, and an overall post count for all topics? so you can maybe list the post count for each topic individualy, but also display an overal count for the whole forum, or whatever it is you're making.. In which case I'd probably have a total posts variable. let's say $totposts, then check the database for all the posts and adding them together as $totposts. <?php $totposts = 0; $sql = "SELECT * FROM $tablereplies"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { $totpost++ } }else{ echo "no posts"; } }else{ echo mysql_error(); } ?> that basically increments $totposts for each post in the database. I hope that's along the lines of what you wanted... Quote Link to comment https://forums.phpfreaks.com/topic/51240-little-help/#findComment-252420 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.