Jump to content


Photo

Inbox %


  • Please log in to reply
5 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 21 September 2006 - 10:59 AM

hey,
I have a pm system for my users, and I allow each member to have 50 Pms
this is set within the database when they register so, admins and mods get
more storable messages and I can give different users moreif i wanted etc.
the problem is trying to tell php that the Database value (50 in this case)
is 100% then make it calculate how much percent 3 messages would be.

to us that's 6% ... but if you know what i mean?
if you can help would be nice.
-Ash

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 21 September 2006 - 11:04 AM

floor($msgs_in_inbox/$max_allowed*100);

Is this good?

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 21 September 2006 - 11:05 AM

How are you storing the information in the database?  Are you storing each of the users messages in a row and then doing a count() or do you have a column in the user table that says how many messages they've sent?

We're going to get MySQL to do the work for you before passing the data to the php.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#4 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 21 September 2006 - 11:26 AM

Well their Max limit is within their user table...
and their Inbox Messages is counted via mysql_num_rows();

by your comment it sounds like i will need to change my code
to something like...

$sql = mysql_query("SELECT COUNT(*) FROM table WHERE pm_to='$variable'");
$num = mysql_num_rows( $sql );

if that's right, then using Orio's help; i will make...
$num = mysql_num_rows( $sql );
$max = "50"; //would make sql get this var.
$Pcent = floor($msg/$max*100);
echo "<p>You are using ".$pcent."% of your Inbox quota</p>";


#5 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 21 September 2006 - 11:59 AM

That looks good :)

Orio.
Think you're smarty?

(Gone until 20 to November)

#6 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 21 September 2006 - 01:06 PM

:] Yep it worked, I didn't need to use the count(); :/
but it works alright thanks guys!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users