Jump to content

Percentages


Canman2005

Recommended Posts

Hi all

 

I have a simple query, it looks like

 

$sql = "SELECT * FROM `thisdata` WHERE `id` = 1";
$query = @mysql_query($sql,$connection) or die(mysql_error());
while ($row = mysql_fetch_array($query))
{
$datavalue1 = $row['dataone'];
$datavalue2 = $row['datatwo'];
$datavalue3 = $row['datathree'];
$datavalue4 = $row['datafour'];
$datavalue5 = $row['datafive'];
}

 

now each $datavalue (1-5) holds a number, so the above may give

 

$datavalue1 = 12

$datavalue2 = 342

$datavalue3 = 4532

$datavalue4 = 2

$datavalue5 = 767

 

there isnt always 5 values, sometimes there maybe just 2, 3 or 4 values, such as

 

$datavalue1 = 54

$datavalue2 = 2

$datavalue3 =

$datavalue4 =

$datavalue5 =

 

is it possible to gather all the values given and then provide a percentage out of 100 for each one, so if I had 3 values then there % would be as follows

 

$datavalue1 = 36 - would equal 18%

$datavalue2 = 64 - would equal 32%

$datavalue3 = 100 - would equal 50%

$datavalue4 =

$datavalue5 =

 

Does this make sense?

 

Can anyone help

 

thanks

 

ed

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.