PDA

View Full Version : hurry up~~i need help


squawell
12-11-2001, 11:35 AM
i make this code

$boardviews = $DB_site->query_first("SELECT SUM(views) AS totalviews FROM thread");
$totalviews = number_format($boardviews[totalviews]);
$countviews=$DB_site->query_first("SELECT count(views) AS views FROM thread WHERE postuserid='$bbuserinfo[userid]'");
$myviews=number_format($countviews[views]);
$percentviews = round(($myviews / $totalviews) * 100,2);

but it always show up the same number~~

what's wrong??

Admin
12-11-2001, 11:48 AM
1. number_format() adds commas to the number and thus you won't be able to use it correctly in mathematic operations. So don't number_format() $boardviews[totalviews] or $countviews[views] before calculating $percentviews.

2. This:
SELECT count(views) AS views FROM thread WHERE postuserid='$bbuserinfo[userid]'
should have SUM as well.

squawell
12-11-2001, 12:08 PM
oh~~~but i change this code

$boardviews = $DB_site->query_first("SELECT SUM(views) AS totalviews FROM thread");
$totalviews = $boardviews['totalviews'];
$countviews=$DB_site->query_first("SELECT SUM(views) AS views FROM thread WHERE postuserid='$bbuserinfo[userid]'");
$myviews=$countviews['views'];
$percentviews = round(($myviews / $totalviews) * 100,2);

but the have same problem

PS:i user this code in member.php

squawell
12-11-2001, 12:11 PM
i think the problem is this code

$countviews=$DB_site->query_first("SELECT SUM(views) AS views FROM thread WHERE postuserid='$bbuserinfo[userid]'");
$myviews=$countviews['views'];

it only can show up admin's views~~~

any idea??