Jump to content

How Can i log Users Post in my Database?


scheols

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.