scheols Posted July 18, 2006 Share Posted July 18, 2006 Alright im a lil confused ??? how can i make my database know that when a user makes a topic or a reply that it counts up as a post and log it in my DB? Quote Link to comment https://forums.phpfreaks.com/topic/14913-how-can-i-log-users-post-in-my-database/ Share on other sites More sharing options...
zq29 Posted July 18, 2006 Share Posted July 18, 2006 You can get a count like this, then just pop that value back into the right table.[code=php:0]$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `posts` WHERE `member_id`='$mid'"),0);[/code]Or you can just run a query every time the user makes a post.[code=php:0]mysql_query("UPDATE `members` SET `posts`=`posts`+1 WHERE `id`='$mid'") or die(mysql_error());[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14913-how-can-i-log-users-post-in-my-database/#findComment-59813 Share on other sites More sharing options...
scheols Posted July 18, 2006 Author Share Posted July 18, 2006 i dont understand^ so i tried this:[code]<?php ob_start(); include("config.php"); $count_user_post = mysql_query("SELECT post FROM replies WHERE username = '$logged[username]' ") or die(mysql_error()); $count_user_row = mysql_fetch_array($count_user_post); $count_add = $count_user_row['post']; mysql_query("UPDATE users SET posts = '$count_add'+1 WHERE username = '$logged[username]' ");?>[/code]but when i post it only adds 1 and it doesnt increase Quote Link to comment https://forums.phpfreaks.com/topic/14913-how-can-i-log-users-post-in-my-database/#findComment-59825 Share on other sites More sharing options...
hackerkts Posted July 18, 2006 Share Posted July 18, 2006 SA means that, after the line where you put "INSERT blah blah blah" (this is where after the user hit the submit and make a post), below it you just put another query[code] $count_user_post = mysql_query("SELECT post FROM replies WHERE username = '$logged[username]' ") or die(mysql_error()); $count_user_row = mysql_fetch_array($count_user_post); $count_add = $count_user_row['post']; mysql_query("UPDATE users SET posts = '$count_add'+1 WHERE username = '$logged[username]' ");[/code]Overall:After a user made a post, it will auto update their post count. Quote Link to comment https://forums.phpfreaks.com/topic/14913-how-can-i-log-users-post-in-my-database/#findComment-59841 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.