Code To Show Total In/out Messages..

Started on the old forum in July 2008 · view the original in the archive · old links redirect here

9 replies · 566 views · started 18 years ago · 1 min read

3 participants
Guest #1

Currently in user profiles i use this code to display total incoming /outgoing messages by that user..

mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE touid='".$who."'"));

and

mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE byuid='".$who."'"));

The problem i have to periodically reset the private table to reduce load on server, and doing this reset the values to zero . How can i store these values in users table so that it doesnt get reset to zero on truncating the private table and keeps getting updated with the messages received or sent too?? I hope u understand.. I have been trying this since many days, but no success.. i think i am missing out on something small.. :sad:

It would be great if someone helps.. I am talking about the lava script btw..

Thanx.

Guest #3

yeah thats why... i want the number of messages should be stored in the user table, and they shud be displayed in the profile from user table instead of private table... each time a new message or a message is being sent, both the private and user table shud be updated.. in this way the displaying of messages in profile wont reset to zero on truncating the private table...

synergyx Developer · 100 posts #4

i think what he means is that he would like to see the total of all users

eg: user 1 5/10 user 2 10/1 user 3 6/3

total: 21/14

does that make sense of what you wanna do?

Guest #6

no.. not total of all users.. Alright, forget what i said earlier.. i want to know, what should i do, so that the total in/out messages doesnt reset to zero even on truncating the private table.. Can they be stored in some other table too?? If yes, how?

crazybrumi Super moderator Principal · 1,064 posts #7

yu will get 0/0 even if yu put it anywer else or itl be an incorrect result. the only thing i can think of is make a new field in users and then get a coutner started so the total sent and total recieved this would be on its own and not connected to anything else. abit same to the visit counter

Want something coded email me at sales@webnwaphost.com for a prices.

http://flagcounter.com/more/W80q

Guest #8

Look at this code...

$noin = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE touid='".$uid."'"));
$nout = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_private WHERE byuid='".$uid."'"));

$prin = mysql_fetch_array(mysql_query("SELECT totin FROM ibwf_users WHERE id='".$uid."'"));
$prout = mysql_fetch_array(mysql_query("SELECT totout FROM ibwf_users WHERE id='".$uid."'"));

if($noin[0]>$prin[0])
{$diff = ($noin[0]-$prin[0])
 $res = mysql_query("UPDATE ibwf_users SET totin='".$diff[0]."' WHERE id='".$uid."'");}

if($nout[0]>$prout[0])
{ $diff = ($nout[0]-$prout[0])
$sql = mysql_query("UPDATE ibwf_users SET totout='".$diff[0]."' WHERE id='".$uid."'");}

I created two fields totin and totout in users table.. The rest of the code is self explanatory... But obviously its buggy.. Now if anyone could modify it, so that it works..

thanx..

wizard Senior · 493 posts #9

put this in ur core.php

function pm_in_out($to,$from)
{
    $in_q  = mysql_fetch_array(mysql_query("SELECT totin FROM ibwf_users WHERE id='".$to."'"));
    $in    = $in_q[0]+1;
    $do    = mysql_query("UPDATE ibwf_users SET totin='".$in."' WHERE id='".$to."'");
    $out_q = mysql_fetch_array(mysql_query("SELECT totout FROM ibwf_users WHERE id='".$from."'"));
    $out   = $out_q[0]+1;
    $do2   = mysql_query("UPDATE ibwf_users SET totout='".$out."' WHERE id='".$from."'");
}

and in ur inboxproc.php where u have

  if($res)
  {

    echo "<img src=\"images/ok.gif\" alt=\"O\"/>";
    echo "PM was sent successfully to $whonick

";
    echo parsepm($pmtext, $sid);
    
  }else{

put

  if($res)
  {
pm_in_out($who,$byuid);
    echo "<img src=\"images/ok.gif\" alt=\"O\"/>";
    echo "PM was sent successfully to $whonick

";
    echo parsepm($pmtext, $sid);
    
  }else{
Guest #10

Great!! Thanx Wizard!! Thats what i wanted!! 🙂 Was trying to do it other way.. This method is easier.. thanx.. 🙂

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close