In a Russian card game I'm trying to keep statistics of how often a player swears (says "bad words" - and we do have a lot of them in Russian language) in the following PostgreSQL table:
# select * from pref_chat order by swear desc;
id | swear | lines
-------------------------+-------+-------
OK194281930260 | 3 | 153
OK350321778615 | 2 | 127
DE12770 | 2 | 339
OK122898831181 | 2 | 63
OK349829847011 | 2 | 126
OK215240745969 | 1 | 66
OK459742722980 | 1 | 96
And I need to generate an integer number of this data - between 1 and 100 (overflowing is okay) - so that I can create the following "swear'o'meter:
So I'm trying (with PHP 5.3 at CentOS 6.2):
$sth = $db->prepare('select swear, lines from pref_chat where id=?');
$sth->execute(array($id));
if ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
$quotient = 100 * floor(20 * $row['swear'] / (1 + $row['lines']));
print('<p><img src="https://chart.googleapis.com/chart?chs=700x100&cht=gom&chco=00FF00,FFFF00,FF0000&chxt=x&chxl=0:|Swearometer&chd=t:' . $quotient . '" width=700 height=100 alt="Swearometer"></p>)';
}
Unfortunately I get zero - because PHP is probably doing an "integer division".
I've tried to prepend floor() to $row['swear'] and $row['lines'] to "cast" them to float - but this didn't help.
UPDATE:
Sorry, I had a typo in my original question... The $quotient is really 0, I print it out. I've also tried the following, but still zero:
$quot = 100 * floor(20 * $row['swear'] / (.1 + $row['lines']));