0

The below code displays correctly, I need an "IF" statement that prevents displaying rows with 0% in the percent column and I've tried several conditions. None are working.

I only want to display rows that has at least 1% in the percent column.

Here is the code:

$result = mysql_query("SELECT user8, concat(round(count( * ) *100 /
(SELECT count( * )
FROM `lm_users`)) , \"%\")
AS percent
FROM `lm_users` GROUP BY user8
");
while ($row = mysql_fetch_array($result))

for ($i=0; $i<mysql_num_fields($result); $i++)
echo $row[$i] . " ";
echo "<br>";

Any help would be appreciated.

Edited by pritaeas: Fixed markdown.

3
Contributors
3
Replies
33
Views
3 Years
Discussion Span
Last Post by minitauros
0

What about adding something like WHERE percent > 0 to your statement? :)

On a side note: I'm not sure if this is an efficient query. I'm not a MySQL expert, but for as far as my knowledge goes I think this query is executing its subquery a lot of times (each time a record is fetched, it has to execute the subquery). Why don't you just make two queries? One fetching the maximum COUNT from lm_users, and then one that fetches all the records. You could use PHP to do the percentage calculations. Anyone here with more information on this?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.