开发者

When selecting an amount of rows, how can I select a percentage of a percentage?

开发者 https://www.devze.com 2022-12-29 05:37 出处:网络
Fairly simple question: Say I want to use 30 percent of the rows in the table of my MySQL table. However I also have a user input where they can select a percentage of that percentage

Fairly simple question:

Say I want to use 30 percent of the rows in the table of my MySQL table.

However I also have a user input where they can select a percentage of that percentage

For example: $_GET['percentage']% of 30%

so we say that $_GET['percentage'] = 30

开发者_Python百科

How would I select 30% (or $_GET['percentage']) of 30% to use in a while loop?


30% of any value is that value multiplied by 0.3.

So 30% of 30% is 0.3 * 0.3 = 0.09, or 9%.

Substitute in whatever numbers you desire.


Multiplication?

.3 * $_GET['percentage'] / 100.0


You can use mysql_num_rows or PDOStatement::rowCount depending on which library your using to get the number of rows returned by the query and then simple multiplication can tell you how many times you should call mysql_fetch_row or PDOStatement::fetch.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号