Canman2005 Posted December 5, 2007 Share Posted December 5, 2007 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted December 5, 2007 Share Posted December 5, 2007 Instead of SELECT *, select just the values you want SELECT dataone, datatwo, datathree, datafour, datafive FROM ... Now $row contains just these values. $total = array_sum ($row); foreach ($row as $val) { if ($val) echo $val*100/$total; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.