Jump to content

New Post Count Display


Stotty

Recommended Posts

Im using this code to add up my Post count (creds Blade )

 

$sql = mysql_query("SELECT posts FROM km_users WHERE playername = '$player'");
$sql = mysql_fetch_assoc($sql);
$posts = $sql['posts'];
$sql = mysql_query("UPDATE km_users SET posts = '".($posts + 1)."' WHERE playername = '$player'");

 

thats on post.php and reply.php

 

its adding perfect ive got 2 users on called "k" and one called "one" one has 5 posts and k has 3

 

if on messages.php i add this code

 

$sql = mysql_query("SELECT posts FROM km_users WHERE playername = '$player'");
$sql = mysql_fetch_assoc($sql);
$posts = $sql['posts'];
  print "<br>";
  print "Posts :";
  echo $posts;

 

it displays 3 Posts for every user that would be K's post count

 

how can i make it display each users post count not just 1 users

 

my mysql is like this

 

CREATE TABLE `km_users` (
  `ID` bigint(21) NOT NULL auto_increment,
  `status` int(11) NOT NULL default '0',
  `playername` varchar(15) NOT NULL default '',
  `password` varchar(255) NOT NULL default '',
  `email` varchar(255) NOT NULL default '',
  `validated` int(11) NOT NULL default '0',
  `validkey` varchar(255) NOT NULL default '',
  `tsgone` bigint(20) NOT NULL,
  `oldtime` bigint(20) NOT NULL default '0',
  `lasttime` bigint(20) NOT NULL default '0',
  `posts` int(11) NOT NULL,
  PRIMARY KEY  (`ID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;

 

Thanks in advanced

Link to comment
https://forums.phpfreaks.com/topic/138992-new-post-count-display/
Share on other sites

Not solving the problem just making this more efficient:

 

$sql = mysql_query("UPDATE km_users SET posts = (`posts`+1) WHERE playername = '$player'");

 

I believe that is all you would need to add 1 to posts, saves you from having to select each time.

 

As for your real issue, make sure you are not entering the same playername each time and that it is being changed properly.

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.