e1seix Posted August 9, 2010 Share Posted August 9, 2010 Hello hello. Have been searching for a pie chart script to use, which I have now found. However the code requires the following data: $data = array( 'IE7' => 22, 'IE6' => 30.7, 'IE5' => 1.7, 'Firefox' => 36.5, 'Mozilla' => 1.1, 'Safari' => 2, 'Opera' => 1.4, ); My issue is that I have the name (ie. IE6) and percentage value (ie. 30.7) stored in a mysql database. How can I translate it to the array with the help of an sql statement to list each individual table entry and their respective percentage value? EG. $query = 'SELECT * FROM list WHERE percentage > "0.00"'; $results = mysql_query( $query ) or die( mysql_error() ); while( $row = mysql_fetch_array( $results ) ) { ... <etc.> echo $row["name"]; echo $row["percentage"]; ... } [/code[ Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/210257-array-help/ Share on other sites More sharing options...
sasa Posted August 9, 2010 Share Posted August 9, 2010 $query = 'SELECT * FROM list WHERE percentage > "0.00"'; $results = mysql_query( $query ) or die( mysql_error() ); while( $row = mysql_fetch_array( $results ) ) { ... <etc.> echo $row["name"]; echo $row["percentage"]; $data[$row["name"]] = $row["percentage"]; } Quote Link to comment https://forums.phpfreaks.com/topic/210257-array-help/#findComment-1097250 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.