Jump to content


Photo

How Can i log Users Post in my Database?


  • Please log in to reply
3 replies to this topic

#1 scheols

scheols
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 18 July 2006 - 05:20 AM

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?
Dont Piss me Off today

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 18 July 2006 - 06:52 AM

You can get a count like this, then just pop that value back into the right table.
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM `posts` WHERE `member_id`='$mid'"),0);
Or you can just run a query every time the user makes a post.
mysql_query("UPDATE `members` SET `posts`=`posts`+1 WHERE `id`='$mid'") or die(mysql_error());


#3 scheols

scheols
  • Members
  • PipPipPip
  • Advanced Member
  • 113 posts

Posted 18 July 2006 - 07:45 AM

i dont understand^ so i tried this:

<?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]' ");
?>

but when i post it only adds 1 and it doesnt increase
Dont Piss me Off today

#4 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 18 July 2006 - 09:10 AM

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
$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]' ");

Overall:
After a user made a post, it will auto update their post count.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users